jquery - 无法使用 loadonce 刷新 jqgrid : true

标签 jquery jqgrid refresh

在创建/编辑/删除一行后,我显然需要从服务器刷新网格。 我已经检查了奥列格关于重新加载的所有问题,但仍然无法使其工作。我究竟做错了什么?这么简单的事情为什么要搞得这么复杂。

我还想在发布后关闭表单..但这是下一步

这是我的代码:

$(function(){ 
         var roles = null;
                $.ajax({
                    'async': false,
                    'global': false,
                    'url': '<?php echo base_url().'utils/Admin_Rest/get_roles'?>',
                    'dataType': 'json',
                    'success': function (data) {
                        roles = data;
                    }
                });
var comptes=$("#Comptes");
comptes.jqGrid({
            url:'<?php echo base_url().'utils/Admin_rest/get_comptes'?>',    
            mtype : "post",           
            datatype: "json",           
            colNames:['Nom','Prenom','Email','Utilisateur','Telephone', 'Password','Role'],   
            colModel:[  
                {name:'first_name',index:'first_name',editable:true, editrules: { required: true }, edittype:'text',search:false, align:"center"},
                {name:'last_name',index:'last_name',editable:true, edittype:'text', editrules: { required: true }, search:false,  align:"center"},
                {name:'email',index:'email',editable:true, editrules: { required: true }, edittype:'text',search:false, align:"center"},
                {name:'username',index:'username',editable:true, editrules: { required: true }, edittype:'text',search:false, align:"center"},
                {name:'phone',index:'phone',editable:true, editrules: { required: true }, edittype:'text',search:false, align:"center"},
                 {name:'password',index:'password',editable:true, hidden:true, editrules: { edithidden:true }, edittype:'password',search:false, align:"center"},                       
                {name:'role',index:'role', editable:true, editrules: {required: true},  edittype:'select', search:true, stype:'select', 
                    searchoptions:{ value:roles},
                    editoptions:{ value:roles}}
                ],

            rowNum:10,
            jsonReader: {
                 root: "rows", 
                  page: "page", 
                  total: "total", 
                  records: "records", 
                  repeatitems: false, 
                  id: "id",
                  userdata: "userdata"
            },                  
            width: 850,
            height: "100%",
            rowList:[10,20,30],
            pager: '#pager',
            sortname: 'id',
            viewrecords: true,
            loadonce:true,
            rownumbers: true,
            gridview: true,
            pagination:true,
            editurl: "<?php echo base_url().'utils/Admin_rest/edit_compte'?>",  

            caption:""
            }).navGrid('#pager',
                    {edit:true,
                    add: true, 
                    del:true,refresh:false},
              { // edit options
                    beforeShowForm: function(frm) { 
                        comptes.jqGrid('setColProp', 'password', {editrules: {required: false}});
                    }
                }, 
                { // add options
                    beforeShowForm: function(frm) { 
                        comptes.jqGrid('setColProp', 'password', {editrules: {required: true}});
                }
                });

comptes.jqGrid('navGrid', '#pager', {refresh: false},
        { // Edit options
            afterSubmit: function () {
                $(this).jqGrid('setGridParam', {datatype:'json'});
                return [true,'']; // no error
            }
        },
        { // Add options
            afterSubmit: function () {
                $(this).jqGrid('setGridParam', {datatype:'json'});
                return [true,'',false]; // no error and no new rowid
            }
        },
        { // Delete options
            afterSubmit: function () {
                $(this).jqGrid('setGridParam', {datatype:'json'});
                return [true,'']; // no error
            }
        }
    );
});

最佳答案

好像参数给错了。正确的寻呼机参数是:

.navGrid('#pager',
                    {edit:true,
                    add: true, 
                    del:true,refresh:false},
              { // edit options
                    beforeShowForm: function(frm) { 
                        comptes.jqGrid('setColProp', 'password', {editrules: {required: false}});
                    },
                    afterSubmit: function() {
                        comptes.jqGrid('setGridParam',{datatype:'json'}).trigger('reloadGrid');
                          return [true,'',false]; // no error and no new rowid
                         }
                }, 
                { // add options
                    beforeShowForm: function(frm) { 
                        comptes.jqGrid('setColProp', 'password', {editrules: {required: true}});
                    },
                     afterSubmit: function() {
                            comptes.jqGrid('setGridParam',{datatype:'json'}).trigger('reloadGrid');
                        return [true,'']; // no error
                    }
                } ,
                { // delete options
                     afterSubmit: function() {
                            comptes.jqGrid('setGridParam',{datatype:'json'}).trigger('reloadGrid');
                        return [true,'']; // no error
                    }
                }       
               );

关于jquery - 无法使用 loadonce 刷新 jqgrid : true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11897649/

相关文章:

jqgrid - 如何增加放置在JQGRID顶部的过滤器工具栏的高度

javascript - jqGrid 覆盖禁用我页面的其余部分

jquery - 动态更新谷歌元标签是否可取?如果通过 ajax 请求更新,谷歌是否会更新描述和标题等元标记?

jquery - 所有浏览器都使用 HTML5 的带有 pur CSS3 的粘性页脚(高度未知)

jquery - 使用 Mousemove 和左键单击滚动浏览一堆图像

javascript - Guriddo jqGrid with Bootstrap 中 ‘shrinktofit’ 参数设置为“true”的 setGridWidth 方法中的问题

android - TabActivity 上的 NFC Intent 启动新 Activity 而不是刷新现有 Activity

html - 单击/提交到 iframe 后刷新整个页面

html - 浏览器刷新行为

javascript - jquery scroller 需要一次向下移动一个内容