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

Revert Multiselect to original state?

1 Answer 25 Views
MultiSelect
This is a migrated thread and some comments may be shown as answers.
chris
Top achievements
Rank 1
chris asked on 01 Nov 2013, 10:47 PM
I have a multiselect widget that gets its initial values from my model and then reads from a datasource to get options.  What i'd like to do provide users a button they can click to revert all changes made to the multiselect. 

My Multiselect definition is below:
@(Html.Kendo().MultiSelect()
         .Name(AMultiName)
         .DataTextField("PrettyText")
         .DataValueField("MapAbbreviation")
         .Placeholder("Edit EMR maps...")
         .Filter(FilterType.Contains).MinLength(3)
         .AutoBind(false)
         .DataSource(
             ds => ds.Read(r=>r.Action("ReadMapOptions","EmrMappingKendo", new {Area="Messaging"})).ServerFiltering(true))
         .Value(ASelectedOptions)
         .Events(e =>
             {
                 e.Change("onChangeEvent");
                 e.DataBound("saveInitialMultiValues");
             })
         )
On the databound I invoke a function where i copy the existing value and _dataItems array into new arrays (this way i have what the original state of the widget was).  Then in my function that is invoked by my cancel button i try to set the .value and .dataItem properties of the multiselect and refrech them but the UI doesn't update.  Can someone see my flaw?

 //function invoked by dataBound   
function saveInitialMultiValues(multi) {
        multi.sender._originaldataItems = multi.sender._dataItems.slice(0);
        multi.sender._originalValues = multi.sender._values.slice(0);
    }
//function invoked by my cancel button
function cancelMultiSelectUpdates(multiId) {
     var multi = $('#' + multiId);
     var temp = multi.data("kendoMultiSelect");
     temp._dataItems = temp._originaldataItems;
     temp._values = temp._originalValues;
     refresh();
 }
Ive debugged it and my array values are copied to my placeholder arrays and then back into the _values and _dataItems array properly but the UI doesn't reflect the change....

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 05 Nov 2013, 09:00 AM
Hello Chris,

 
I will suggest you use the API of the widget. The value in this case can be used to set/clear the selected data of the widget.

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
chris
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or