1. #1
    Sencha User
    Join Date
    Aug 2008
    Posts
    101
    Vote Rating
    6
    FoxMulder900 is on a distinguished road

      0  

    Default Sorting a timestamp using the datecolumn

    Sorting a timestamp using the datecolumn


    Sorting a datecolumn works nicely for basic dates; however I have noticed that it does not properly sort by time of day.

    Here is an example using a modified version of the example found in the documentation for datecolumn:
    Code:
    Ext.create('Ext.data.Store', {
        storeId:'sampleStore',
        fields:[
            {name: 'timestamp',   type: 'date', dateReadFormat: 'd-m-Y @ h:i A'}                      
        ],
        data:[
            { timestamp: '12-02-2013 @ 01:58 PM' },
            { timestamp: '12-02-2013 @ 02:03 PM' },
            { timestamp: '12-02-2013 @ 02:04 PM' },
            { timestamp: '12-02-2013 @ 02:05 PM' },
            { timestamp: '13-02-2013 @ 01:00 PM' },
            { timestamp: '11-02-2013 @ 01:00 PM' }
        ],
        sortOnLoad: true,
        sorters: [{
            property:'timestamp',
            direction: 'DESC'
        }]
    });
    
    
    Ext.create('Ext.grid.Panel', {
        title: 'Date Column Demo',
        store: Ext.data.StoreManager.lookup('sampleStore'),
        forceFit: true,
        columns: [
            {header: 'Timestamp', dataIndex: 'timestamp', xtype: 'datecolumn', format:'d-m-Y @ h:i A'}
        ],
        height: 200,
        width: 450,
        renderTo: Ext.getBody()
    });
    The idea here is that the most recent dates should appear at the top of the list, however you will notice that '12-02-2013 @ 01:58 PM' appears below '12-02-2013 @ 02:03 PM'.

    Is the date column purely meant for basic dates without a timestamp and disregards them? I know that I could write a custom sort function to take them into account, but I wanted to make sure I wasn't missing something before I do so.

  2. #2
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    17,054
    Vote Rating
    659
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    No, the problem is you're specifying the data directly on the store which means it never gets passed through the reader, so the type is never a date. If you want to force the data through the reader, see:

    http://docs.sencha.com/ext-js/4-0/#!/api/Ext.grid.Panel

    By specifying the proxy/reader.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

Thread Participants: 1