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

Selection disappears...

2 Answers 178 Views
MultiSelect
This is a migrated thread and some comments may be shown as answers.
Daniel Blendea
Top achievements
Rank 1
Daniel Blendea asked on 16 Dec 2019, 12:54 PM

I have a model bound via MVVM with a collection of related entities:

01.@(Html.Kendo().MultiSelectFor(m => m.AmendedRegulations)
02.    .DataTextField("Title")
03.    .DataValueField("Id")
04.    .Animation(false).AutoBind(false)
05.    .HtmlAttributes(new
06.    {
07.        @class = "form-control",
08.        data_bind = "value: regulation.AmendedRegulations"
09.    })
10.    .Filter(FilterType.Contains)
11.    .AutoClose(false)
12.    .DataSource("amendedRegulationsDataSource")
13.)

 

The data structure retrieved by amendedRegulationsDataSource and AmendedRegulation have {Id : int, Title: string}.

01.let amendedRegulationsDataSource = new kendo.data.DataSource({
02.    serverFiltering: false,
03.    transport: {
04.        read: {
05.            url: "@ViewData["ApiUrl"]/regulations/regulations-for-dropdowns",
06.            dataType: "json",
07.            type: "GET",
08.            data: function() {
09. 
10.                return { datasetId : viewModel.regulation.DatasetId }
11.            }
12.        }, 
13.    }
14.});

 

01.$(function () {
02.  
03.    languagesDataSource.read();
04.  
05.    viewModel.regulationDataSource.fetch(function() {
06.  
07.        viewModel.set("regulation", this.data()[0]);
08.        kendo.bind($("#edit-regulation"), viewModel);
09.  
10.        // amendedRegulationsDataSource.read();
11.    });
12.});

 

When kendo.bind executes, the data in AmendedRegulations is bound, is displayed in the multi select, however, when I click the multi select, to maybe change the selection, the selected items disappear, which causes confusion to the user.

Now, is there a setting that I need to make/activate in order to preserve the selected items in the multi select?

 

Thank you.

 

2 Answers, 1 is accepted

Sort by
0
Daniel Blendea
Top achievements
Rank 1
answered on 16 Dec 2019, 01:52 PM

I found the solution:

1. remove .AutoBind(false) from the multiselect's declaration.

2. remove DataSource("amendedRegulationsDataSource") from the multi select's declaration.

3. add "source: amendedRegulationsDataSource" to the data_binding declaration.

4. move the amendedRegulationsDataSource inside the viewModel definition.

The same solution applies also to the Dropdownlist problem that I mentioned (https://www.telerik.com/forums/inconsistent-behaviour)

 

01.@(Html.Kendo().MultiSelectFor(m => m.AmendedRegulations)
02.    .DataTextField("Title")
03.    .DataValueField("Id")
04.    .Animation(false)
05.    .HtmlAttributes(new
06.    {
07.        @class = "form-control",
08.        data_bind = "value: regulation.AmendedRegulations, source: amendedRegulationsDataSource"
09.    })
10.    .Filter(FilterType.Contains)
11.    .AutoClose(false)
12.)

 

0
Martin
Telerik team
answered on 19 Dec 2019, 11:18 AM

Hello Daniel,

I am glad you were able to resolve the issue and thank you for sharing the solution. It would be helpful for other members encountering the same problem.

Feel free to contact us whenever you have further questions.

Regards,
Martin
Progress Telerik

Get quickly onboarded and successful with Telerik UI for ASP.NET Core with the dedicated Virtual Classroom technical training, available to all active customers.
Tags
MultiSelect
Asked by
Daniel Blendea
Top achievements
Rank 1
Answers by
Daniel Blendea
Top achievements
Rank 1
Martin
Telerik team
Share this question
or