This is a migrated thread and some comments may be shown as answers.

multiselect angularjs - filter datasource without sort

4 Answers 231 Views
MultiSelect
This is a migrated thread and some comments may be shown as answers.
software
Top achievements
Rank 1
software asked on 12 Jan 2015, 09:21 AM
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!

4 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 14 Jan 2015, 09:00 AM
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!
 
0
software
Top achievements
Rank 1
answered on 15 Jan 2015, 09:04 AM
thanks Georgi  - Ill try give you a working example shortly.
0
software
Top achievements
Rank 1
answered on 15 Jan 2015, 02:14 PM
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
0
Georgi Krustev
Telerik team
answered on 19 Jan 2015, 11:20 AM
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!
 
Tags
MultiSelect
Asked by
software
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
software
Top achievements
Rank 1
Share this question
or