【问题标题】:JqGrid Reload not workingJqG​​rid重新加载不起作用
【发布时间】:2010-08-09 15:57:55
【问题描述】:

我在使用 Jqgrid 时遇到问题,我在一个页面上有两个网格,单击第一个网格的一行需要重新加载第二个网格。

我 100% 确定第二个网格配置正确,如果我手动传递一个硬编码的 id,它会正确填充。

只是重新加载功能不起作用。请有人帮忙。下面是两个网格的 jquery 代码

$(document).ready(function() {      
    jQuery("#list2").jqGrid({ 
        url:'classes/ListServices.php', 
        datatype: "json",
        mtype: 'POST', 
        colNames: ['Id','Description', 'Details', 'Cost in (R)'], 
        colModel: [ 
            {name:'Id',index:'Id', align:"center", width:30}, 
            {name:'Description',index:'Description', align:"center"}, 
            {name:'Details',index:'Details', align:"left"}, 
            {name:'Cost',index:'Cost',align:"center",width:30,formatter:'currency'},
        ],
        width: 780,
        height: 100, 
        rowNum:18, 
        pager: '#pager1',
        loadonce: true,
        sortname: 'id',
        viewrecords: true,
        sortorder: "asc", 
        caption:"Services List",
        multiselect: false,
        onSelectRow: function(ids) {
            if(ids == null) { 
                ids=0; 
                if(jQuery("#list3").jqGrid('getGridParam','records') >0 ) {
                    jQuery("#list3").jqGrid('setGridParam',
                                           {url:"subgrid.php?q=1&id="+ids,page:1});
                    jQuery("#list3").jqGrid.trigger('reloadGrid'); 
                } 
            } 
            else { 
                jQuery("#list3").jqGrid('setGridParam',
                                        {url:"subgrid.php?q=1&id="+ids,page:1}); 
                jQuery("#list3").jqGrid.trigger('reloadGrid'); 
            }       
        }  
    }); 

    jQuery("#list2").jqGrid('navGrid','#pager2',
                            {edit:false,add:false,del:false,multipleSearch:true});
    jQuery("#list2").jqGrid('filterToolbar',
                            {stringResult: true,searchOnEnter : false});

    jQuery("#list3").jqGrid({ 
        url:'classes/ListServicesDetails.php?Id=2', 
        datatype: "json",
        mtype: 'POST', 
        colNames: ['Id','ServiceId', 'Description', 'Details', 'Cost in (R)'], 
        colModel: [ 
           {name:'Id',index:'Id', align:"center", width:30},
           {name:'ServiceId',index:'ServiceId', align:"center", width:30},  
           {name:'Description',index:'Description', align:"center"}, 
           {name:'Details',index:'Details', align:"left"}, 
           {name:'Cost',index:'Cost',align:"center",width:30,formatter:'currency'},
        ],
        width: 780,
        height: 200, 
        rowNum:18, 
        pager: '#pager2',
        loadonce: true,
        sortname: 'id',
        viewrecords: true,
        sortorder: "asc", 
        caption:"Services Details List",
        multiselect: false,
        onSelectRow: function(id) {
            alert(id);
        }  
    }); 
    jQuery("#list3").jqGrid('navGrid','#pager2',
                            {edit:false,add:false,del:false,multipleSearch:true});
});  

如果有人可以帮助我,请...

谢谢

【问题讨论】:

    标签: php jqgrid


    【解决方案1】:

    两个 jqGrids 都有参数loadonce: true。这意味着在第一次加载后,网格的datatype 将从"json" 更改为"local"。要重新加载第二个网格,您应该将 datatype 参数与 urlpage 参数一起重置为 "json"

    【讨论】:

    • 嗨,奥列格,谢谢一百万 - 100% 有效。如果我之前没有说过 - 这个论坛摇滚!谢谢
    • 这对我也有用,我也不需要设置 url 或页面参数,谢谢!
    • @Will:欢迎您! jqGrid.trigger('reloadGrid') 之前的 url 设置是针对问题的,但大多数情况下建议设置page:1。原因如下。让我们用户在数据刷新前选择第5页,重新加载后总页数为4。如果不重置page用户刷新后可以看到第5页是空的,不明白原因这。要立即解决此问题,您可以在reloadGrid 之前设置page:1。另见stackoverflow.com/questions/3807623/jqgrid-paging-question/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-04
    • 2011-03-11
    • 2013-10-15
    • 1970-01-01
    相关资源
    最近更新 更多