JqG​​rid:对本地数据进行排序

编程入门 行业动态 更新时间:2024-10-25 10:24:28
本文介绍了JqG​​rid:对本地数据进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在此示例中,我对本地数据排序存在一些问题.排序不起作用,我也不知道原因.您能在我的代码中解释问题吗?

I have some problem with local data sorting in this example. Sorting doesn't work and I don't know reason of it. Could you explain problem in my code?

<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>

P.S.在此演示中,使用本地数据进行排序也不起作用. www.ok-soft-gmbh/jqGrid/LocalReader.htm

P.S. Sorting also doesn't work in this demo with local data. www.ok-soft-gmbh/jqGrid/LocalReader.htm

推荐答案

您是对的:jqGrid在使用datatype: "local"且使用localReader: {repeatitems: true}格式的data参数时,在使用datatype: "local"时存在错误.

You are right: jqGrid have bug in usage datatype: "local" with data parameter in localReader: {repeatitems: true} format.

有很多方法可以修复该错误.最简单的一个似乎是我要替换线条

There are many ways to fix the bug. One from the most easy one seems me to replace the lines

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); } }

演示使用固定代码,现在可以正常使用.稍后,我将发布相应的请求请求以及对trirand的建议修复.

The demo uses the fixed code and it works correctly now. I will post later the corresponding pull request with suggested fix to trirand.

已更新:我在请求请求中发布了该修补程序的更好实现. 更新2:我的拉取请求已经合并到 jqGrid在github上的主要代码.您可以在jquery.jqGrid.srs.js上进行相同的更改,然后从此处.无论如何,下一版的jqGrid(版本高于4.6.0)将包含所描述问题的修复程序.

UPDATED: I posted better implementation of the fix in the pull request. UPDATED 2: My pull request is already merged to the main code of jqGrid on the github. You can do the same changes on jquery.jqGrid.srs.js, download the modified file from here. In any way the next version of jqGrid (version higher as 4.6.0) will contains the fix of described problem.

更多推荐

JqG​​rid:对本地数据进行排序

本文发布于:2023-10-30 03:31:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1541636.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据   JqG   rid

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!