Results 1 to 4 of 4

Thread: How to sort store by multiple fields?

  1. #1
    Sencha User
    Join Date
    Jan 2013
    Location
    Salvador, Bahia - Brazil
    Posts
    35

    Default How to sort store by multiple fields?

    I'm trying to sort a store by two fields, but only the first sort works.
    Store is loaded in controller. The data is requested but only first sort is applied.
    Code:
    Ext.define('Events', {
        extend: 'Ext.data.Store',
        config: {
            model: 'Event',
            storeId: 'events',
            sorters: [
                {
                    property: 'timestamp',
                    direction: 'ASC'
                },
                {
                    property: 'title',
                    direction: 'ASC'
                }
            ]
        }
    });
    Code:
    Ext.define('Event', {
        extend: 'Ext.data.Model',
        config: {
            idProperty: 'id',
            fields: [
                {name: 'id', type: 'int'},
                {name: 'title', type: 'string'},
                {name: 'description', type: 'string'},
                {name: 'image', type: 'string'},
                {name: 'url', type: 'string'},
                {name: 'category'},
                {name: 'tags'},
                {name: 'timestamp'}
            ]
        }
    });
    Only sort by the first sorter.
    I tryed this another code in store on sorters field
    Code:
            sorters: [
                {
                    sorterFn: function (event1, event2) {
                        console.log('sorter 1');
                        var data1 = event1.get('datetime').valueOf().toString(),
                            data2 = event2.get('datetime').valueOf().toString();
                        return data1.localeCompare(data2);
                    },
                    direction: 'ASC'
                },
                {
                    sorterFn: function (event1, event2) {
                        console.log('sorter 2');
                        var title1 = event1.get('title'),
                            title2 = event2.get('title');
                        return title1.localeCompare(title2);
                    },
                    direction: 'ASC'
                }
            ]
    And on the console only print severals 'sorter 1' and no one 'sorter 2'.
    How I can sort by multiple fields?

    This don't work too
    Code:
    var store = Ext.getStore('events');
    store.sort([            {
                    sorterFn: function (event1, event2) {
                        console.log('sorter 1');
                        var data1 = event1.get('datetime').valueOf().toString(),
                            data2 = event2.get('datetime').valueOf().toString();
                        return data1.localeCompare(data2);
                    },
                    direction: 'ASC'
                },
                {
                    sorterFn: function (event1, event2) {
                        console.log('sorter 2');
                        var title1 = event1.get('title'),
                            title2 = event2.get('title');
                        return title1.localeCompare(title2);
                    },
                    direction: 'ASC'
                }
            ]);

  2. #2
    Sencha User joel.watson's Avatar
    Join Date
    Nov 2014
    Posts
    3,120
    Answers
    446

    Default

    Hi--

    It seems to be working for me (simplified example):

    https://fiddle.sencha.com/#fiddle/10nd (see console)

    Thanks!
    Joel

  3. #3
    Sencha User
    Join Date
    Jan 2013
    Location
    Salvador, Bahia - Brazil
    Posts
    35

    Default

    How I can detect what's going on in my app?!

  4. #4
    Sencha User joel.watson's Avatar
    Join Date
    Nov 2014
    Posts
    3,120
    Answers
    446

    Default

    Quote Originally Posted by luciano.lima View Post
    How I can detect what's going on in my app?!
    Can you share a working test case of the issue you're experiencing?

    https://fiddle.sencha.com

    Thanks
    Joel

Similar Threads

  1. Multiple fields sort
    By cristi_vladan in forum Ext 2.x: User Extensions and Plugins
    Replies: 19
    Last Post: 5 Jun 2017, 4:20 PM
  2. Replies: 1
    Last Post: 9 Oct 2012, 6:51 AM
  3. sortInfo Sort by multiple fields
    By ValterBorges in forum Ext 3.x: Help & Discussion
    Replies: 7
    Last Post: 18 Feb 2010, 10:54 PM
  4. this.fields is undefined in store.sort after sorting grid column
    By bradlymathews in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 23 Mar 2009, 3:50 PM

Tags for this Thread

Posting Permissions

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