Results 1 to 6 of 6

Thread: How to change the default sort mechanism of grid column

  1. #1

    Default Answered: How to change the default sort mechanism of grid column

    Helllo All
    I am willing to have custom sorting mechanism for column sorting in grid. Is there any hook EXT has provided for such custom sorting ?
    Thanks
    Samir


  2. #2
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,258
    Answers
    759
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  3. #3

    Default

    Thanks Evan ...
    That helps .
    Thank you very much

  4. #4
    Sencha User adityavarma.mca's Avatar
    Join Date
    Jun 2012
    Location
    Hyderabad
    Posts
    6

    Default Thanks Evant...

    It saved my time....
    -Regards
    Aditya.K.
    +91 9014447669.
    [email protected]

  5. #5
    Sencha User
    Join Date
    Sep 2013
    Posts
    30
    Answers
    1

    Default

    It looks like sortType can only sort a list on the model level. Is there a way to define a sort on the grid column?


  6. #6
    Sencha User
    Join Date
    Mar 2011
    Location
    Arvada, CO
    Posts
    404
    Answers
    11

    Default

    Quote Originally Posted by mwilliamsShields View Post
    It looks like sortType can only sort a list on the model level. Is there a way to define a sort on the grid column?
    I know this is a bit late, but I came up with a way of doing it for columns in Ext JS 5, seeing as how doSort was taken out. I decided to listen to the sortchange event, and from there, use the Ext.data.Store.setSorters method. Excuse the complex sorterFn, but here's the relevant code (and Fiddle):

    Code:
    // grid class
    initComponent: function() {
      ...
      this.on('sortchange', this.onSortChange, this);
    },
    
    onSortChange: function(container, column, direction, eOpts) {
      // check for dayColumnIndex
      if (column && column.dayColumnIndex !== undefined) {
        this.sortColumnByIndex(column.dayColumnIndex, direction);
      }
    },
    
    sortColumnByIndex: function(columnIndex, direction) {
      var store = this.getStore();
      if (store) {
        var sorterFn = function(rec1, rec2) {
          var sortValue = false;
          if (rec1 && rec2) {
            var day1;
            var daysStore1 = rec1.getDaysStore();
            if (daysStore1) {
              day1 = daysStore1.getAt(columnIndex);
            }
            var day2;
            var daysStore2 = rec2.getDaysStore();
            if (daysStore2) {
              day2 = daysStore2.getAt(columnIndex);
            }
            if (day1 && day2) {
              sortValue = day1.get('value') > day2.get('value');
            }
          }
          return sortValue;
        };
        if (direction !== 'ASC') {
          sorterFn = function(rec1, rec2) {
            var sortValue = false;
            if (rec1 && rec2) {
              var day1;
              var daysStore1 = rec1.getDaysStore();
              if (daysStore1) {
                day1 = daysStore1.getAt(columnIndex);
              }
              var day2;
              var daysStore2 = rec2.getDaysStore();
              if (daysStore2) {
                day2 = daysStore2.getAt(columnIndex);
              }
              if (day1 && day2) {
                sortValue = day1.get('value') < day2.get('value');
              }
            }
            return sortValue;
          };
        }
        // this is the key to it all right here
        store.setSorters([{
          sorterFn: sorterFn
        }]);
      }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •