1. #1
    Sencha Premium Member
    Join Date
    Aug 2008
    Posts
    209
    Answers
    4
    Vote Rating
    4
    squarefan is on a distinguished road

      0  

    Default Unanswered: Store - sorting not working reliably

    Unanswered: Store - sorting not working reliably


    Hi@all,

    I am experiencing problems with sorters. I tried both defining sort directly in the store with a sorter and also to sort separately (I want to change sorting of store/list on the push of a button - which I have implemented already but it doesn't work reliable - sorts are messed up most of the time).

    The value I am trying to sort is of the type float... but somehow it just doesn't re-arrange the store correctly (talking about ~40-50items) that is linked to a list. My understanding is that when I re-arrange the store that the list is updated automatically since I can see the list change when I call e.g. store.sort('bla', 'DESC').

    As mentioned also defining a sorter directly on the store does not work correctly/reliably

    Code:
                sorters: [
                    {
                        sorterFn: function(record1, record2) {
                            return parseFloat(record1.get('distance')) > parseFloat(record2.get('distance')) ? 1 : (parseFloat(record1.get('distance')) === parseFloat(record2.get('distance')) ? 0 : -1);
                        },
                        direction: 'ASC'
                    }
                ],
    also

    Code:
    store.sort('distance', 'DESC')
    returns inconsistent sorting!

    Is there a proper way maybe to manually sort a store / re-arranging the items in the worst case with a loop?

    Help would be greatly appreciated.

    cheers,
    Alex

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,073
    Answers
    3500
    Vote Rating
    853
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    So you sort the store once and it works but if you sort it again it doesn't work?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha Premium Member
    Join Date
    Aug 2008
    Posts
    209
    Answers
    4
    Vote Rating
    4
    squarefan is on a distinguished road

      0  

    Default


    No, also on the first sort it sorts the first ~20 elements correctly and then it is all mumbled. If I set the store to remote sort true and load it via the backend it is correct though.

    If I want to sort locally it doesn't matter if I define it directly in the store or afterwards with the .sort() method... it is not reliable and will return almost random results. I am using 2.0.0 at this time.. 2.1 exhibits the same problem - I temporarily upgraded to that version to test it as well.

    Any help on this is greatly appreciated.

    thanks,
    Alex

  4. #4
    Sencha Premium Member
    Join Date
    Aug 2008
    Posts
    209
    Answers
    4
    Vote Rating
    4
    squarefan is on a distinguished road

      0  

    Default


    Nobody an idea? What would be the most efficient way to manually sort the store?

    thanks,
    Alex

  5. #5
    Sencha User
    Join Date
    Apr 2010
    Location
    China
    Posts
    227
    Answers
    64
    Vote Rating
    20
    haduki will become famous soon enough haduki will become famous soon enough

      0  

    Default


    "distance" and "bla"
    why you sort different fields in one sorter?
    I write English by translator.

  6. #6
    Sencha Premium Member
    Join Date
    Aug 2008
    Posts
    209
    Answers
    4
    Vote Rating
    4
    squarefan is on a distinguished road

      0  

    Default


    Sorry thats my bad - it is actually only one field per sort (corrected the sample)

    So I would like to sort by distance DESC; the store type is defined as float... but it is not correctly sorted. Also if I remove the sorter and do it manually via store.sort('distance', 'DESC') it does not sort correctly.

    At the end I want to sort between two different values via the .sort method but it seems that the sorter just sorts it randomly even though I pass the values correctly (either directly at the store or via the .sort method).

    cheers,
    alex

  7. #7
    Sencha Premium Member
    Join Date
    Aug 2008
    Posts
    209
    Answers
    4
    Vote Rating
    4
    squarefan is on a distinguished road

      0  

    Default


    I saw that the store has a method _autoSort: true and I suspect this is the problem. Is there a possiblity to disable any kind of auto behaviour to avoid issues like this?

    thanks,

Thread Participants: 2