2012-09-05 115 views
0

我有一个需要编辑的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});  


} 

回答

0

我做了以下迫使电网重载:

.navGrid('#pager', 
        {edit:true, 
        add: true, 
        del:true,refresh:false}, 
       { // edit options 

        afterSubmit: function() { 
         comptes[0].clearToolbar(); 
         comptes.jqGrid('setGridParam',{datatype:'json'}).trigger('reloadGrid'); 
          return [true,'',false]; // no error and no new rowid 
         } 
       }, 
       { // add options 

        afterSubmit: function() { 
          comptes[0].clearToolbar(); 
          comptes.jqGrid('setGridParam',{datatype:'json'}).trigger('reloadGrid'); 
         return [true,'']; // no error 
        } 
       } , 
       { // delete options 
        afterSubmit: function() { 
          comptes[0].clearToolbar(); 
          comptes.jqGrid('setGridParam',{datatype:'json'}).trigger('reloadGrid'); 
         return [true,'']; // no error 
        } 
       }  
       ); 
+0

感谢您的帮助。它通过弹出的编辑对话框完成编辑。不过,我想编辑表格中的数据。现在,当数据被编辑并从网格本身保存而不使用弹出窗口时,我想要一个afterSubmit来触发以刷新表格。我在哪里放置我的提交后/我如何实现这一目标。 – MilindaD

+0

http://stackoverflow.com/questions/2109754/jqgrid-reload-grid-after-successfull-inline-update-inline-creation-of-record – Samson

0

尝试与您的所有编辑处理后的新数据加载的jqGrid如下:

jQuery("#grid").jqGrid('setGridParam',{datatype:'json'}).trigger('reloadGrid');