我有一個需要編輯的Jqgrid。我已成功設置網格以在編輯後保存數據,但問題是,當保存數據時,網格不會隨數據庫中存在的數據一起刷新。例如,版本字段由應用程序後端自動更新,但編輯完成後,它不刷新,並顯示舊值。我試過 後提交 afterCompleteJQGrid刷新數據從服務器ater更新數據編輯
哪些沒有工作。我還在其中放置了一個警報,以驗證該功能是否被調用,但是警報沒有顯示。此外,我將loadonce設置爲false,並將reloadaftersubmit設置爲true,但這也不起作用。我認爲這個問題可能是我沒有正確配置編輯或將上述參數放在錯誤的位置。
保存完成後(編輯)更新的數據(這是整個頁面)返回給Jqgrid(作爲json)。這裏的問題是顯示的是舊數據,如何在編輯後顯示更新的數據。
更新:我發現,當我通過彈出框編輯執行afterSubmit。但是通過格式選項進行編輯可以編輯表格中的數據。現在,當數據被編輯並從網格本身保存而不使用彈出窗口時,我想要一個afterSubmit來觸發以刷新表格。我在哪裏放置我的提交後/我如何實現這一目標。
/**
* Initialize and Draw JQGrid
* @return
*/
function drawFOMJQGrid(){
var lastsel2;
jQuery("#tblGrid").jqGrid({
height: 180,
width:990,
datatype: "json",
colNames:['','Hotel','Outlet','Major Group','Item Group','Version'],
jsonReader : {
root: "regDetails",
page: "page",
total: "total",
records: "records",
repeatitems: false
},
colModel:[
{name: 'myac', width:80, fixed:true, sortable:false, resize:false, formatter:'actions', formatoptions:{keys:true}},
{name:'hotelName',index:'hotelName',align:"left",width:30,resizable:false},
{name:'majorGroupName',index:'majorGroupName',align:"left", width:20,resizable:false},
{name:'itemGroupName',index:'itemGroupName', width:30,align:"left",resizable:false},
{name:'version',index:'version', width:20,align:"right",resizable:false,editable:true,hidden: false}
],
onSelectRow: function(id){
},
/*afterSubmit : function(response, postdata){
alert("AAAA");
},
afterComplete : function(response, postdata){
alert("AAAA2");
}, */
//rowList:[10,20,30],
rowNum:5,
pager: '#divGridPg',
sortname: 'hotelName',
viewrecords: true,
sortorder: "outletName",
gridview: true,
bgiframe: true,
autoOpen: false,
caption: 'POS Item Pricing',
forceFit: false,
loadtext: 'Loading ...',
sortable: true,
loadonce: false,
editurl: "itemPricingSave.action", //"/js/itemPricing/server.js",
datatype: "json"
});
$("#tblGrid")[0].addJSONData(regGridJSONData);
$("#tblGrid").setGridParam({datatype: 'json'});
jQuery("#tblGrid").jqGrid('navGrid','#divGridPg',{edit:true,add:false,del:false,reloadAfterSubmit:true});
}
/**
* Initialize and Draw JQGrid
* @return
*/
function drawFOMJQGrid(){
var lastsel2;
jQuery("#tblGrid").jqGrid({
height: 180,
width:990,
datatype: "json",
colNames:['','Hotel','Outlet','Major Group','Item Group','Version'],
jsonReader : {
root: "regDetails",
page: "page",
total: "total",
records: "records",
repeatitems: false
},
colModel:[
{name: 'myac', width:80, fixed:true, sortable:false, resize:false, formatter:'actions', formatoptions:{keys:true}},
{name:'hotelName',index:'hotelName',align:"left",width:30,resizable:false},
{name:'majorGroupName',index:'majorGroupName',align:"left", width:20,resizable:false},
{name:'itemGroupName',index:'itemGroupName', width:30,align:"left",resizable:false},
{name:'version',index:'version', width:20,align:"right",resizable:false,editable:true,hidden: false}
],
onSelectRow: function(id){
},
/*afterSubmit : function(response, postdata){
alert("AAAA");
},
afterComplete : function(response, postdata){
alert("AAAA2");
}, */
//rowList:[10,20,30],
rowNum:5,
pager: '#divGridPg',
sortname: 'hotelName',
viewrecords: true,
sortorder: "outletName",
gridview: true,
bgiframe: true,
autoOpen: false,
caption: 'POS Item Pricing',
forceFit: false,
loadtext: 'Loading ...',
sortable: true,
loadonce: false,
editurl: "itemPricingSave.action", //"/js/itemPricing/server.js",
datatype: "json"
});
$("#tblGrid")[0].addJSONData(regGridJSONData);
$("#tblGrid").setGridParam({datatype: 'json'});
jQuery("#tblGrid").jqGrid('navGrid','#divGridPg',{edit:true,add:false,del:false,reloadAfterSubmit:true});
}
感謝您的幫助。它通過彈出的編輯對話框完成編輯。不過,我想編輯表格中的數據。現在,當數據被編輯並從網格本身保存而不使用彈出窗口時,我想要一個afterSubmit來觸發以刷新表格。我在哪裏放置我的提交後/我如何實現這一目標。 – MilindaD
http://stackoverflow.com/questions/2109754/jqgrid-reload-grid-after-successfull-inline-update-inline-creation-of-record – Samson