gpt4 book ai didi

jquery - jqgrid 成功内联更新/内联创建记录后重新加载网格

转载 作者:行者123 更新时间:2023-12-03 21:45:32 28 4
gpt4 key购买 nike

我想知道如何在行内联编辑后触发 reloadGrid。

<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");
}

我已经创建了一个重新加载方法,但我不确定将其放在哪里。我尝试过:

jQuery('#grid').jqGrid('editRow',id,true,reload());

但是当用户单击一行时这已经被调用。上面的代码允许用户单击一行,然后按 Enter 键提交数据并更新或创建记录。

用户创建新对象后,我必须重新加载网格,因为我需要新创建对象的对象 ID,以便进一步编辑该行。

编辑:解决方案:

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;
}
}
},

更新:供将来引用。所有从 js grids 开始的用户也可以看看 Slickgrid因为我从 jqgrid 切换到 slickgrid,只能推荐它。

最佳答案

这是 editRow 函数的语法

jQuery("#grid_id").jqGrid('editRow', rowid, keys, oneditfunc, succesfunc, url, extraparam, aftersavefunc, errorfunc, afterrestorefunc);

oneditfunc: fires after successfully accessing the row for editing, prior to allowing user access to the input fields. The row's id is passed as a parameter to this function.

succesfunc: if defined, this function is called immediately after the request is successful. This function is passed the data returned from the server. Depending on the data from server; this function should return true or false.

aftersavefunc: if defined, this function is called after the data is saved to the server. Parameters passed to this function are the rowid and the response from the server request.

在您的情况下,如果您想在保存行后重新加载网格,则对 editRow 方法的调用应如下所示。

jQuery('#grid').jqGrid("editRow", id, true, '', '', '', '', reload)

我已分配您的reload函数,该函数会为“aftersavefunc”参数重新加载网格

重新加载方法本身应定义如下

function reload(rowid, result) {
$("#grid").trigger("reloadGrid");
}

关于jquery - jqgrid 成功内联更新/内联创建记录后重新加载网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2109754/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com