JqG​​rid:本地数据的排序

2024-01-06

在此示例中,我在本地数据排序方面遇到一些问题。排序不起作用,我不知道原因。你能解释一下我的代码中的问题吗?

<table id="list" ></table>
<div id="pager"></div>
<script type="text/javascript">
    var myData =  [
                        { id: "1",  cell: ["1", "test"] },
                        { id: "2",  cell: ["2", "test2"] },
                        { id: "3",  cell: ["3", "test3"] },
                        { id: "4",  cell: ["4", "test4"] }
    ];
jQuery("#list").jqGrid({
    data: myData,
    datatype: "local",
    colNames: ['MyId','Client'],
    colModel: [{ name: 'MyId', index: 'MyId', width: 100, align: 'left' ,  sortable: true},
               { name: 'Client', index: 'Client', width: 100, align: 'left', sortable: true }],
    rowNum:10,
    rowList:[10,20,30,100],
    pager: '#pager',
    sortname: 'Id',
    localReader: {repeatitems: true},          
    viewrecords: true,
    sortable: true,
    sortorder: "asc",
    caption: "Tests",
    loadonce: true
});
jQuery("#list").jqGrid('navGrid', '#pager', { edit: false, add: false, del: false });

</script>

附:在此演示中,排序也不适用于本地数据。http://www.ok-soft-gmbh.com/jqGrid/LocalReader.htm http://www.ok-soft-gmbh.com/jqGrid/LocalReader.htm


你是对的:jqGrid在使用中有bugdatatype: "local" with data参数输入localReader: {repeatitems: true} format.

有很多方法可以修复该错误。我似乎要替换最简单的一个线条 https://github.com/tonytomov/jqGrid/blob/v4.6.0/js/grid.base.js#L1551-L1555

if(locdata || ts.p.treeGrid===true) {
    rd[locid] = $.jgrid.stripPref(ts.p.idPrefix, idr);
    ts.p.data.push(rd);
    ts.p._index[rd[locid]] = ts.p.data.length-1;
}

与以下

if(locdata || ts.p.treeGrid===true) {
    rd[locid] = $.jgrid.stripPref(ts.p.idPrefix, idr);
    ts.p.data.push(rd);
    ts.p._index[rd[locid]] = ts.p.data.length-1;
} else if (ts.p.datatype === "local" && dReader.repeatitems) {
    var idStripted = $.jgrid.stripPref(ts.p.idPrefix, idr),
        iData = ts.p._index[idStripted];
    if (iData !== undefined && ts.p.data != null && ts.p.data[iData] != null) {
        $.extend(true, ts.p.data[iData], rd);
    }
}

The demo http://www.ok-soft-gmbh.com/jqGrid/LocalReader1.htm uses 固定代码 http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-4.6.0/js/jquery.jqGrid.src-localReaderRepeatitemsTrue.js现在它可以正常工作了。我稍后将发布相应的拉取请求以及对 trirand 的建议修复。

UPDATED:我在中发布了更好的修复实施拉取请求 https://github.com/tonytomov/jqGrid/pull/621. 更新2:我的拉取请求已经merged https://github.com/tonytomov/jqGrid/commit/9f03534b4cfe60ae682874e0f6465778f813d1f1 to jqGrid的主要代码在github上 https://github.com/tonytomov/jqGrid。您可以在以下位置进行相同的更改jquery.jqGrid.srs.js,从下载修改后的文件here http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-4.6.0/js/jquery.jqGrid.src-localReader.js。无论如何,jqGrid 的下一个版本(版本更高,如 4.6.0)将包含所描述问题的修复。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

JqG​​rid:本地数据的排序 的相关文章

随机推荐