Author Topic: Sort Blank cells at the end on ascending  (Read 316 times)

mikep

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 163
    • View Profile
Sort Blank cells at the end on ascending
« on: May 27, 2023, 05:33:34 pm »
I have a number/int column and I'd like the rows with no data to be sorted last, rather than first, in the ascending sort.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: Sort Blank cells at the end on ascending
« Reply #1 on: May 29, 2023, 10:43:00 pm »
Please use custom sorting:

Code: [Select]
sortType: function (rowData1, rowData2, dataIndx) {
                    var c1 = rowData1[dataIndx],
                        c2 = rowData2[dataIndx];

                    if (c1 > c2 || c1 == null) {
                        return 1;
                    }
                    else if (c1 < c2 || c2== null)  {
                        return -1;
                    }
                    else {
                        return 0;
                    }
                }

mikep

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 163
    • View Profile
Re: Sort Blank cells at the end on ascending
« Reply #2 on: May 31, 2023, 09:56:19 pm »
thank you that works. However when clicking the column header to sort, the columns are sorted in 4 different ways: ascending, descending, custom sort asc, custom sort descending. is there a way to only apply the custom sort when sorting ascending, so the user only toggles between 2 sorts: custom asc, and descending

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: Sort Blank cells at the end on ascending
« Reply #3 on: June 01, 2023, 05:13:30 pm »
Please set sortModel.cancel to false.

https://paramquery.com/pro/api#option-sortModel