【问题标题】:jqGrid sorting on client sidejqGrid在客户端排序
【发布时间】:2011-01-09 00:45:36
【问题描述】:

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

但每次我单击排序列标题时,它发出一个 Ajax 调用以进行排序,但我只需要使用本地数据进行就地排序。

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

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

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

【问题讨论】:

标签: javascript jquery ajax sorting jqgrid


【解决方案1】:

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

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

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

editurl: "clientArray"
datatype: "local"

【讨论】:

  • 您好,请您详细说明一下#groups 是什么?
  • 只是网格的ID。我刚刚更改了 ID 以尝试澄清这一点。
  • 谢谢你,虽然我不完全理解你的解决方案。 Groxx 在stackoverflow.com/questions/1329002/… 的另一个答案可以解决问题。以防万一其他人感兴趣...
【解决方案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...",
        });
    }); 

【讨论】:

    【解决方案3】:
    $(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...",
            });
        }); 
    

    【讨论】:

    • 请也解释一下代码,这样它就更有教育意义了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-09
    • 2011-03-12
    • 1970-01-01
    • 2012-02-20
    • 2014-11-18
    相关资源
    最近更新 更多