Author Topic: Sorting Issue for columns with blank empty values  (Read 1834 times)

cijojohn

  • Pro Ultimate
  • Jr. Member
  • *
  • Posts: 73
    • View Profile
Sorting Issue for columns with blank empty values
« on: November 18, 2017, 05:38:00 pm »
Hi Team,

while sorting, the columns with blank values are coming at the top. Please see the behavior in the attached screen shot.

In Snapshot, we have done sorting on column1. You can see the values in Column1 after sort. The values which are empty for the sorted column (column1) in rows are coming up and non-empty cell values are coming at the bottom.


But, we always want these empty values to be appear at the bottom irrespective of sort order. Please suggest the way to make this as default behavior in our grid.


paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Sorting Issue for columns with blank empty values
« Reply #1 on: November 20, 2017, 06:16:12 pm »
Please check this:

http://jsfiddle.net/ue4j6vta/

Code: [Select]
  dir = (ui.sorter[0] || {}).dir;

Code: [Select]
sortType: function(rd1, rd2, di) {
       
var val1 = rd1[di]||"",
        val2 = rd2[di]||"";
          if(val1=="" && val2==""){
          return 0;
          }
          else if(val1==""){
          return dir=="up"? 1: -1;
          }
          else if(val2==""){
          return dir=="up"? -1: +1;
          }
          else{
          return val1>val2? 1: ((val1==val2)?0: -1);
          }
      }
« Last Edit: November 20, 2017, 06:47:37 pm by paramquery »