jqGrid在客户端排序

时间:2010-01-25 09:29:17

标签: javascript jquery ajax sorting jqgrid

我有一个带有自动加载行的树形网格。目标是按树列对网格进行排序,位于客户端

但每次我点击排序列标题时,发出 Ajax调用进行排序,但我需要的是使用本地数据进行就地排序。

我是否有不正确的网格参数或树树上的客户端排序没有树?

用于排序的当前jqGrid参数是:

loadonce: true, // to enable sorting on client side
sortable: true //to enable sorting

3 个答案:

答案 0 :(得分:6)

要让客户端排序正常工作,我需要在加载网格后调用reloadGrid

loadComplete: function() {
    jQuery("#myGridID").trigger("reloadGrid"); // Call to fix client-side sorting
}

我没有必要在我的应用程序中的另一个网格上执行此操作,因为它被配置为使用通过另一个AJAX调用检索的数据,而不是由网格直接检索的数据:

editurl: "clientArray"
datatype: "local"

答案 1 :(得分:2)

我在jqGrid上使用客户端排序,并在选择列表更改时检索一组新的json数据。您需要将rowTotal设置为高于或等于返回的行数,然后在重新加载网格之前将数据类型设置为“json”。

// Select list value changed
$('#alertType').change(function () {
        var val = $('#alertType').val();
        var newurl = '/Data/GetGridData/' + val;
        $("#list").jqGrid().setGridParam({ url: newurl, datatype: 'json' }).trigger("reloadGrid");        
});

// jqGrid setup
$(function () {
        $("#list").jqGrid({
            url: '/Data/GetGridData/-1',
            datatype: 'json',
            rowTotal: 2000,
            autowidth: true,
            height:'500px',
            mtype: 'GET',
            loadonce: true,
            sortable:true,
            ...
            viewrecords: true,
            caption: 'Overview',
            jsonReader : { 
                root: "rows", 
                total: "total", 
                repeatitems: false, 
                id: "0"
            },
            loadtext: "Loading data...",
        });
    }); 

答案 2 :(得分:1)

$(function () {
        $("#list").jqGrid({
            url: '/Data/GetGridData/-1',
            datatype: 'json',
            rowTotal: 2000,
            autowidth: true,
            height:'500px',
            mtype: 'GET',
            loadonce: true,
            sortable:true,
            ...
            viewrecords: true,
            caption: 'Overview',
            jsonReader : { 
                root: "rows", 
                total: "total", 
                repeatitems: false, 
                id: "0"
            },
            loadtext: "Loading data...",
        });
    }); 
相关问题