I have a fairly complicated situation, in which I have a kendo grid that has some details for each record. Inside those details, there is a kendo multiselect that offers server side filtering capabilities. I want to be able to "edit" the details of each record and change the value of the multiselect. In the case that the user decides to cancel the modification, I want to be able to revert back to the old values for the input.
The code i am using for this is the following:
function onEditCancel(e) {
revertMultiSelect(e.model.uid);
//using the uid will help us to only revert the desired multiselect
}
function revertMultiSelect(uid)
{
var originalState = originalStateDictionary[uid];
//this dictionary has the desired initial state
if (originalState != null) {
var multiSelect = $("#my_multiselect" + uid).data("kendoMultiSelect");
multiSelect.dataSource.data(originalState.InitialDataSource);
multiSelect.value(originalState.InitialSelectedIds);
}
}
The process is working completely fine when the only single modification to the multiselect value involves deleting, after clicking cancel on the row, the state of the multiselect is reverted succesfully (old values are prepopulated).
HOWEVER, once I decide to add a new value (after a server side filtering operation has been completed) and I decide to cancel the operation, this stops the revertMultiSelect function stops working as expected.
To be more specific, once the code reaches the line multiSelect.value(originalState.InitialSelectedIds);
filtering is triggered once more with an emtpy value (I can intercept the filtering request on my server side). This is not being triggered when my only operation was to delete a value, and causes the multi select to lose ALL selected values and appear empty.
I get the sense that if I can somehow prevent the filtering to occur on the cancel action, I could stop the multiselect from erasing itself.I have tried resetting the filter as indicated here but had no success.
Is there something I am missing? Greetings Luis.
UPDATE I added the following JSFiddle http://jsfiddle.net/8us1fvy1/2/
Workflow 1:
Workflow 2:
I have no idea if Kendo team is planning to change this behavior so if you can't change on server side code you can add this function to your multiselect dataSource as workaround:
requestStart: function(e){
if(e.sender.filter().filters.length === 0){
// cancel event to prevent sending request to server
e.preventDefault();
// trigger revert function again to set original state data
revertMultiSelect();
}
}
Updated fiddle: http://jsfiddle.net/8us1fvy1/2/