jQWidgets Forums

jQuery UI Widgets Forums Lists DropDownList Best approach to sort the content of a dropdownlost

This topic contains 1 reply, has 2 voices, and was last updated by  Dimitar 11 years, 6 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author

  • Bentechsoft
    Participant

    Hi,

    I have a couple of dropdownlist on page.   They are all binded to knockout observablearray.    I a dataadapter with datatype observablearray.

    The content of the array is structured data (id, name, description).   The field I’m displaying in the dropdown is the name.   Unfortunately, the list is not sorted by name automatically.

    What is the best approach to getting those list sorted?  The approach, I’m thinking of using is the one below .e.i  Using obervablearray.sort() and provide a function that will sort by name.

    this.myobservablearray.sort(function(left, right) { 
          return left.name == right.name ? 0 : (left.name < right.name ? -1 : 1) 
          });

    Is that the way to go?  It seems to work well but maybe there is another way that you would suggest.

    Thank you


    Dimitar
    Participant

    Hello Bentechsoft,

    Yes, this is a suitable way to sort the list.

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.