0

I'm trying to implement a custom sorting where I try creating an impression of ignoring nulls. From the accepted answer here here's how I would go about doing things:

  1. Implement a custom sorting function
  2. In the sorting function I would determine if the sort order is ascending or descending
  3. If the sort order is ascending I would assign a higher value like 1000 so the null values remain at the bottom.
  4. If the sort order is descending I would assign a value of -1 so the null values remain at the bottom.

Is there a way to determine the sort order in custom sorting function? I would appreciate if someone knows a better way of solving this problem.

Community
  • 1
  • 1
Siddharth
  • 167
  • 1
  • 2
  • 13

1 Answers1

0

This is how I solved this problem.
In the colModel I defined the column like

colModel:[
   ...

 {
    name: 'HD Column', width: 50,
    sorttype: function (cellObj, rowObj) {
      var sortColumnName = grid.jqGrid('getGridParam', 'sortname');
      var sortOrder = grid.jqGrid('getGridParam', 'sortorder');
      if (sortOrder === 'desc') {
        return ((cellObj === null || cellObj === '') ? -1000 : Number(cellObj));
      }
      else if (sortOrder === 'asc') {
        return ((cellObj === null || cellObj === '') ? 50000 : Number(cellObj));
      }
   }
...

]
Siddharth
  • 167
  • 1
  • 2
  • 13