Tôi tự hỏi làm thế nào tôi có thể kích hoạt reloadGrid sau khi chỉnh sửa nội tuyến của một hàng.lưới tải lại jqgrid sau khi cập nhật nội tuyến thành công/tạo bản ghi nội tuyến
<script type="text/javascript">
jQuery(document).ready(function(){
var lastcell;
jQuery("#grid").jqGrid({
url:'{{ json_data_handler }}?year={{ get_param_year }}&month={{ get_param_month }}&project_id={{ get_param_project_id }}',
datatype: "json",
mtype: 'GET',
colNames:['hour_record_pk', 'project_pk', 'weekday', 'date', 'sum', 'description'],
colModel:[
{name:'hour_record_pk',index:'hour_record_pk', width:55, sortable:false, editable:true, editoptions:{readonly:true,size:10}},
{name:'project_pk',index:'project_pk', width:55, sortable:false, editable:true, editoptions:{readonly:true,size:10}},
{name:'weekday',index:'weekday', width:300, editable:false, sortable:false},
{name:'date_str',index:'date_str', width:300, editable:true, sortable:false, editoptions:{readonly:true}},
{name:'sum',index:'sum', width:100, editable:true, sortable:true,editrules:{number:true,minValue:0,maxValue:24,required:true}},
{name:'description',index:'description', width:600, editable:true, sortable:false,},
],
jsonReader : {
repeatitems:false
},
rowNum:31,
rowList:[10,20,31],
//pager: jQuery('#gridpager'),
sortname: 'id',
viewrecords: true,
sortorder: "asc",
width: 800,
height: 750,
caption:"Hour Record Overview",
reloadAfterEdit: true, //seems to have no effect
reloadAfterSubmit: true, //seems to have no effect
onSelectRow: function(id){
if(id && id!==lastcell){
jQuery('#grid').jqGrid('restoreRow',lastcell);
jQuery('#grid').jqGrid('editRow',id,true);
lastcell=id;
}
},
editurl:"{% url set_hour_record_json_set %}"
}).navGrid('#gridpager');
});
function reload(result) {
$("#grid").trigger("reloadGrid");
}
tôi đã tạo ra một phương pháp tải lại nhưng tôi không chắc chắn nơi để đặt nó trong tôi đã cố gắng:.
jQuery('#grid').jqGrid('editRow',id,true,reload());
nhưng điều này đã được gọi khi người dùng nhấp chuột vào một hàng. Mã trên cho phép người dùng nhấp vào một hàng và khi nhấn nhập dữ liệu được gửi và bản ghi được cập nhật hoặc tạo.
Sau khi người dùng tạo đối tượng mới, tôi phải tải lại lưới, vì tôi cần id đối tượng của đối tượng mới được tạo, để chăm sóc chỉnh sửa thêm hàng này.
Edit: Các giải pháp:
onSelectRow: function(row_id){
if(row_id != null) {
if(row_id !== last_selected_row) {
jQuery('#grid').jqGrid('restoreRow',last_selected_row);
jQuery('#grid').jqGrid('saveRow',row_id)
.editRow(row_id, true,false,reload);
last_selected_row = row_id;
} else {
last_selected_row=row_id;
}
}
},
Cập nhật: Để tham khảo trong tương lai. Tất cả người dùng bắt đầu với js lưới cũng có thể có một cái nhìn tại Slickgrid như tôi chuyển từ jqgrid để slickgrid và chỉ có thể giới thiệu nó.
Chỉnh sửa cuối cùng của bạn: giải pháp đã giúp tôi rất nhiều. Cảm ơn bạn đã bao gồm. – Tareq
Tôi không thể làm cho mã trên hoạt động, nó cho tôi TypeError: jQuery ("# tnc-list") .jqGrid ("saveRow", row_id) .editRow không phải là hàm – Marvzz
Không hoạt động cho tôi, cuộn xuống mã số – ymakux