jqgrid对不同列上的本地数据进行自定义排序
我有一个 jqgrid,其中 dataytype 是本地的。自动排序对于每一列都运行良好。我想知道是否可以根据另一列对不同列进行排序。 为了更好地解释这一点,让我们假设我有三列 OrderNumber
、Address
、Phone
和一个名为 State
的隐藏列。当单击 Address
列时,我实际上想像单击 State
列一样进行排序。
我正在尝试在 onSortCol
事件上执行此操作,我想要类似的内容:
onSortCol: function (index, iCol, sortorder) {
if(index === "Address"){
//CHANGE SORTED COLUMN TO STATE AND MAKE THE SORT
}
},
I have a jqgrid where dataytype is local. The automatic sort is working fine for each column. I want to know if it's possible to sort a different column based on another column.
To explain this better Lets assume I have three columns OrderNumber
, Address
, Phone
, and a hidden column named State
. When the Address
column is clicked I actually want to sort like if the State
column would have been the one clicked.
I'm trying to do this on the onSortCol
event, I want something like:
onSortCol: function (index, iCol, sortorder) {
if(index === "Address"){
//CHANGE SORTED COLUMN TO STATE AND MAKE THE SORT
}
},
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用远程数据(
datatype:'json'
或datatype:'xml'
),您可以非常轻松地实现任何类型的排序。所以我想你的意思是 jqGrid 与你的问题中的本地数据。在这种情况下,我建议您在定义为函数的colModel
内部使用sorttype
参数。您可以为
Address
列定义sorttype
属性,如下所示:或如下所示:
参数
cellValue
包含将在比较操作中使用的单元格对网格进行排序。rowObject
是代表具有cellValue
的完整行的对象。从函数sorttype
返回另一个值作为cellValue
后,将在比较操作中使用返回的值,而不是cellValue
。在
sorttype
实现的第一个示例中(参见上文),将根据名称为State
的列的包含情况,按Address
列进行排序>。在第二个示例中,具有相同状态的行将另外按地址排序。您可以在此处查看小型演示。如果单击“税”列,网格将按“id”列排序,其中 id 值将被解释为整数。
If you work with remote data (
datatype:'json'
ordatatype:'xml'
) you can implement any kind of sorting very easy. So I suppose that you mean jqGrid with local data in your question. In the case I would recommend you to usesorttype
parameter inside ofcolModel
defined as function.You can define for the
Address
column thesorttype
property which looks like the following:or like this one:
The parameter
cellValue
is the contain of the cell which will be used in compare operation to sort the grid. TherowObject
is the opject which reprecent the full row havingcellValue
. Returnung another value ascellValue
from the functionsorttype
will follow that the returened value will be used in the compare operations instead of thecellValue
.In the first example of
sorttype
implementation (see above) the sorting byAddress
column will be done based on the contain of the column with the nameState
. In the second example, the rows having the same state will be additionaly sorted by address.You can look on the small demo here. If you click on the "Tax" column the grid will be sorted by "id" column where the id values will be interpret as integer.
如果您正在进行服务器端排序,您只需这样做:
您是否尝试过对客户端排序执行相同的操作:
If you were doing server side sorting you would just do this:
Have you tried doing the same for your client side sorting: