How do i sort a column that has multiple types of values? [Trirand JQGrid 4.6]

前端 未结 1 1771
星月不相逢
星月不相逢 2021-01-24 16:58

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 wh

相关标签:
1条回答
  • 2021-01-24 17:43

    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.

    0 讨论(0)
提交回复
热议问题