【问题标题】:How do i sort a column that has multiple types of values? [Trirand JQGrid 4.6]如何对具有多种类型值的列进行排序? [Trirand JQGrid 4.6]
【发布时间】:2016-10-23 04:52:45
【问题描述】:

我在demo website 中使用了 q jqgrid, 'groupd header row config' 版本的 jqgrid。

它生成网格。但假设Notes 列可以包含数字和字符串的场景,因为在某些行中有数字,在某些行中有字符串字符,排序截断并且它仅适用于字符串字符。

场景:假设表格有五行,Notes 列有以下五行数据:

this is good

123

number 123 number

>123.23

<=222.88

我已经使用 sort:true 向 colModel 添加了排序选项,但这仅在注释列具有所有行的字符串字符时才会排序,但如果它具有数字行和字符串字符行的组合则不会排序。我该如何解决这个问题?

【问题讨论】:

    标签: javascript jquery jqgrid


    【解决方案1】:

    jqGrid 包含多种自定义排序的可能性。首先,重要的是要提到以下所有可能性只有在您使用datatype: "local" 或一些远程datatype"json""jsonp""xml")与loadonce: true 结合使用时才有意义。在最后一种情况下,第一次从服务器加载数据后,datatype 将更改为"local"

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

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

    它为您提供了第一种自定义排序方式。例如,您可以使用 RegEx 从callValue 中提取信息的“数字”部分,并从sorttype(您可以在colModel 中为列notes 定义)返回它。有关详细信息,请参阅为 the answer 创建的 the old demo

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

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

    在旧版本的 jqGrid 和

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

    free jqGridsortfunc 允许您实现所需的任何自定义排序行为。有关代码示例,请参见为 the issue 创建的 the demo

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-21
      • 2022-01-07
      • 1970-01-01
      • 2015-12-14
      • 1970-01-01
      • 1970-01-01
      • 2013-02-07
      • 2022-11-23
      相关资源
      最近更新 更多