Author Topic: Sorting with blank cells  (Read 3644 times)

rickpqu

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 26
    • View Profile
Sorting with blank cells
« on: August 12, 2015, 07:06:35 pm »
Hi, in my ParamQuery table, one column has numbers and blanks. When I sort this column, blank cells appear at the top, and then number cells sorted accordingly. Is there a way to make the number cells to show at the top and the blank cells at the bottom after sorting (both ascending and descending)?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6255
    • View Profile
Re: Sorting with blank cells
« Reply #1 on: August 12, 2015, 07:26:58 pm »
It can be done in either of 2 ways.

1) Custom sorting. http://paramquery.com/pro/demos/sorting_custom

or

2) Take out the rows with blank values in beforeSort event and append them in sort event.
Similar example: http://paramquery.com/pro/demos/freeze_rows

rickpqu

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Sorting with blank cells
« Reply #2 on: August 13, 2015, 01:25:10 am »
Thanks. I tried custom sorting, and I could push null cells to the bottom at ascending sorting. However, when I click the column header again for descending sorting, the null cells came to the top, followed by the highest value cells. I guess that descending sorting just reverses the result of ascending sorting - is there a way to custom sorting for both ascending and descending sorting? I am afraid that the option 2) you suggested might take too much time.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6255
    • View Profile
Re: Sorting with blank cells
« Reply #3 on: August 13, 2015, 02:06:25 pm »
Custom sorting column.sortType is called during both ascending and descending order.

you might need to set a flag in beforeSort(evt, ui) event during descending order. you can find the current sorting order from ui.sorter[0].dir

http://paramquery.com/pro/api#event-beforeSort

In sortType callback do the reverse when one of the values is blank and sorting is in descending order.
« Last Edit: August 13, 2015, 05:53:19 pm by paramquery »

rickpqu

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Sorting with blank cells
« Reply #4 on: August 14, 2015, 02:43:25 am »
Thanks. I could solve the problem with using ParamQuery Pro 3's sortModel.sorter and custom sorting (sortType).