如何对具有多种类型值的列进行排序? [Trirand JQGrid 4.6] [英] How do i sort a column that has multiple types of values? [Trirand JQGrid 4.6]

查看:98
本文介绍了如何对具有多种类型值的列进行排序? [Trirand JQGrid 4.6]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在



它会生成网格。但假设senario里的 Notes 列可以包含数字和字符串,因为在某些行中有数字,在某些行中有字符串字符,排序关闭,它只适用于字符串字符。



场景:假设该表有五行而且 Notes 列包含以下五行数据:

 这是好的

123

数字123数字

> 123.23

< = 222.88

我添加了colModel的排序选项使用排序:true但只有当notes列具有所有行的字符串字符时才会排序,但如果它具有数字行和字符串char行的组合则不会。我如何解决这个问题?

解决方案

jqGrid包含多种自定义排序的可能性。首先,重要的是要提到只有使用数据类型:local或某些远程数据类型jsonjsonpxml)与 loadonce:true 组合使用。在最后一种情况下,在第一次从服务器加载数据后,数据类型将更改为local



要对列中的本地数据进行排序,jqGrid必须比较这些值。它做了一些初步的步骤。首先,如果用数组填充数组,则将内容从一列映射到rowid。因此,您可以定义

  sorttype:function(cellValue,item){
return cellValue; //可以返回另一个值为cellValue
}

它为您提供了第一种方式自定义排序。例如,您可以使用RegEx从 callValue 中提取信息的数字部分,并从 sorttype (您可以在 colModel 中为列 notes 定义)。请参阅 /stackoverflow.com/a/5296935/315935\">答案了解更多详情。



第二种方式:定义 sortfunc colModel 中的回调。回调有原型

  sortfunc:function(a,b,direction){
//应返回0, 1或-1
}

旧版本的jqGrid和

  sortfunc:function(a,b,direction,aItem,bItem){
//应该返回0,1或-1
}

in 免费的jqGrid sortfunc 允许您实现所需的任何自定义排序行为。请参阅为演示 -jqgrid / jqGrid / issues / 192rel =nofollow noreferrer>代码示例的问题。


i have used q jqgrid, 'groupd header row config' version of jqgrid in the demo website.

it generates the grid. but assume the the senario where Notes column can contains numbers and string as in some rows there are numbers an in some rows there are string chars, sorting truns off and it only works for strings chars.

scenario:Assume the table has five rows and Notes column has the following data in five rows:

this is good

123

number 123 number

>123.23

<=222.88

i have added the sorting option to colModel ussing sort:true but this only sorts if the notes column has string chars for all the rows but does not if it has a conbination of number rows and string char rows. how do i fix this?

解决方案

jqGrid contains multiple possibilities to customize the sorting. First of all it's important to mention that all the below possibilities have sense only if you use datatype: "local" or some remote datatype ("json", "jsonp", "xml") in combination with loadonce: true. In the last case the datatype will be changed to the "local" after the first loading of data from the server.

To sort the local data in the column jqGrid have to compare the values. It does some preliminary steps. First of all if fills the array with items, which maps the content from one column to the rowid. Thus you can define

sorttype: function (cellValue, item) {
    return cellValue; // another value as cellValue can be returned
}

It gives you the first way of custom sorting. You can for example use RegEx to extract the "number"-part of the information from the callValue and to return it from sorttype (which you can define in colModel for the column notes). See the old demo created for the answer for more details.

The second way: defining of sortfunc callback in colModel. The callback has the prototype

sortfunc: function (a, b, direction) {
    // should return 0, 1 or -1
}

in old versions of jqGrid and

sortfunc: function (a, b, direction, aItem, bItem) {
    // should return 0, 1 or -1
}

in free jqGrid. The sortfunc allows you to implement any custom sorting behavior which you need. See the demo created for the issue for the code example.

这篇关于如何对具有多种类型值的列进行排序? [Trirand JQGrid 4.6]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆