multiselect angularjs - filter datasource without sort

5 posts, 0 answers
  1. Neil
    Neil avatar
    3 posts
    Member since:
    Dec 2010

    Posted 12 Jan 2015 Link to this post

    we are using kendo multiselect within a directive with some custom logic to enable support of very large lists, hence we have a backing object that stores the datasource list, and a backing model to store the selected items.When the user types into the multiselect and selects an item kendo code applies a filter to the datasource and we have mimicked this behavior to remove the fitler kendo applies like so:

    dataSource.filter({});

    In certain cases we need to persist the order in which the items were selected in the multiselect, the issue is that when the above code runs to apply the filter (when the user types into the multiselect and selects an item) in addition to filtering kendo applies a sort on the internal model of the datasource by default it looks like on the items property called 'Name'. In our case its sorting the int values.

    Use case - Imagine you select these items in the multiselect in this sequence: 1 {Id:6, Name:John} 2 {Id:1, Name:Adam}.
    the ng-model on the multiselect correctly shows [6, 1]

    then user types into the multiselect and selects an item {Id: 10, Name: Steve}

    then our code is called: dataSource.filter({}) as we grammatically add the selected items to the multiselect 

    the ng-model on the multiselect is now [1 , 6, 10] // John and Adam have swapped places due to a sort that must have happened in the filter method

    Does anyone know how to filter without having the datasource automatically sort so we can persist the order in which the items were selected? I have tried to use query rather than filter on the datasource with a sort object but my model is an array of int so is becomes complicated as I would have to change these objects in the ng-model...
    ref to datasource query can be seen here: http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#query

    thanks!
  2. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3707 posts

    Posted 14 Jan 2015 Link to this post

    Hi Neil,

    I tested the case in our online demo, but probably I am missing something because the widget behaves as expected. Here is a screencast that I took during the test. Could you share with us more details that will help to observe the depicted issue locally? This will help us to investigate further the problem and follow you with more details.

    Regards,
    Georgi Krustev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Kendo UI is VS 2017 Ready
  4. Neil
    Neil avatar
    3 posts
    Member since:
    Dec 2010

    Posted 15 Jan 2015 in reply to Georgi Krustev Link to this post

    thanks Georgi  - Ill try give you a working example shortly.
  5. Neil
    Neil avatar
    3 posts
    Member since:
    Dec 2010

    Posted 15 Jan 2015 in reply to Neil Link to this post

    Hi Georgi,

    please type AA into the input box and then clear the input then type in 99 and the order of the items in the ng-model is 99,AA

    thanks
  6. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3707 posts

    Posted 19 Jan 2015 Link to this post

    Hello Neil,

    Thank you for the repro demo. I noticed that _.union method actually changes the order of the selected items. If you would like to keep the selected order, then I will suggest you work directly with the array.
    Check the updated test file using the latest official release of Kendo UI. The widget works just fine and the implementation is simplified.

    Regards,
    Georgi Krustev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top
Kendo UI is VS 2017 Ready