Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: Default sort direction of data store in grid

  1. #11

    Default Possible solution

    Quote Originally Posted by spacyspacy View Post
    This applies only to the loading sort of the grid, not the column header click sorts.

    Anyone has found a solution for this problem?
    I am not sure, but I think that should work

    While creating a reader (I'll take for this example XmlReader) object, you have to pass recordType parameter. There you specify list of your names, e.g.
    Code:
    [ 'col1, 'col2', 'col3' ]
    , and this later is passed to Ext.data.Record.create(), according to the docs. And on its documentation there is a config option "sortDir". So if you pass not only the name, but configuration options too, then it should work:

    Code:
    [ {name: 'col1', sortDir: 'DESC'}, 'col2', 'col3' ]
    I think I have tried that, but I am not sure anymore Try and see

  2. #12

    Default

    Quote Originally Posted by cunami View Post
    Code:
    [ {name: 'col1', sortDir: 'DESC'}, 'col2', 'col3' ]
    I think I have tried that, but I am not sure anymore Try and see
    Yeah, that's it, thank you!

  3. #13

    Default

    Quote Originally Posted by spacyspacy View Post
    Yeah, that's it, thank you!
    I'm glad to help

  4. #14
    Sencha User
    Join Date
    Dec 2007
    Posts
    11

    Question

    and what about extjs 4? how do you achieve the same result?

    thanks!

  5. #15
    Ext JS Premium Member
    Join Date
    Apr 2010
    Location
    Midwest, USA
    Posts
    96

    Default

    You should probably post 4.0 topics in 4.0 threads, but here is an override that is your solution that I just made:
    Code:
    Ext.override(Ext.grid.column.Column, {    
        oppositeSort: false,
    
    
        toggleSortState: function() {
            var me = this,
                idx,
                nextIdx;
    
    
            if (me.sortable) {
                idx = Ext.Array.indexOf(me.possibleSortStates, me.sortState);
                if(this.oppositeSort && idx == -1)
                    idx = 0;
    
    
                nextIdx = (idx + 1) % me.possibleSortStates.length;
                me.setSortState(me.possibleSortStates[nextIdx]);
            }
        }
    });
    then in your column config just add the extra attribute oppositeSort: true and it will do what you want.

  6. #16

    Default Ext5 version

    Useful stuff. For those arriving via Google, here's an Ext5 version

    Code:
    Ext.define('Admin.override.Column', {    
        override    : 'Ext.grid.column.Column',
        defaultSort : null,
    
    
        /**
         * Allow a defaultSort property on this column to force 'DESC' order
         * .. This means e.g. the "tracks" column can show popular artists at the top with a single click
         */
        toggleSortState: function() {
            // If this column is already sorted or has no default then goto normal behaviour
            if (this.sortState || this.defaultSort == null) {
                return this.callParent(arguments);
            }
    
    
            // If this column is sortable, apply defaultSort
            if (this.isSortable()) {
                this.sort(this.defaultSort);
            }
        }
    });

Page 2 of 2 FirstFirst 12

Posting Permissions

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