jQuery("#list2").jqGrid(
{
url: 'data/JSONData.json',
datatype :"json",// "local",
colNames : [ 'Inv No', 'Date', 'Client', 'Amount', 'Tax','Total', 'Notes' ],
colModel : [ //jqGrid每一列的配置信息。包括名字,索引,宽度,对齐方式.....
{name : 'id',index : 'id',width : 55,editable:true,editoptions:{readonly:true,size:25}},
{name : 'invdate',index : 'invdate',width : 90,editable:true,editoptions:{size:25}},
{name : 'name',index : 'name asc, invdate',width : 100,editable:true,editoptions:{size:25}},
{name : 'amount',index : 'amount',width : 80,align : "right",editable:true,editoptions:{size:25}},
{name : 'tax',index : 'tax',width : 80,align : "right",editable:true,editoptions:{size:25}},
{name : 'total',index : 'total',width : 80,align : "right",editable:true,editoptions:{size:25}},
{name : 'note',index : 'note',width : 150,sortable : false,editable:true,editoptions:{size:25}}
],
loadonce: true,
rowNum : 10,//一页显示多少条
rowList : [ 10, 20, 30 ],//可供用户选择一页显示多少条
pager : '#pager2',//表格页脚的占位符(一般是div)的id
sortname : 'id',//初始化的时候排序的字段
sortorder : "desc",//排序方式,可选desc,asc
mtype : "post",
editurl: "/edit.ashx",
closeAfterAdd: true,
closeAfterEdit: true,
caption: "Andy JSON Example",
errorTextFormat: function (data) {
return 'Error: ' + data.responseText
},
afterSubmit: function () {
$(this).jqGrid("setGridParam", { datatype: 'json' });
return [true];
}
});
后端返回的是Json结果,
context.Response.Write("{"status":"success"}");
为什么编辑窗口还是新增窗口都是不能关闭,请大家指点,谢谢!
题主配置错了。closeAfterAdd,closeAfterEdit,afterSubmit是jqgrid编辑的配置项,不是jqGrid的配置项,放错位置了
参考:
var navconfig =
{
closeAfterEdit: true,
closeAfterAdd: true,
afterSubmit: function () {
$(this).jqGrid("setGridParam", { datatype: 'json' });
return [true];
}
};
jQuery("#list2").jqGrid({....原来的配置...})
//页脚导航
//注意依次传递.navGrid('#gridpager',{parameters}, prmEdit, prmAdd, prmDel, prmSearch, prmView);中的参数,parameters为是否启用对应的按钮,本示例只启用编辑,添加和刷新按钮
.navGrid('#pager2', { edit: true, add: true, del: false, view: false, search: false, refresh: true }, navconfig, navconfig);
F12,查看控制台有无js错误。