Selection disappears...

3 posts, 0 answers
  1. Daniel Blendea
    Daniel Blendea avatar
    39 posts
    Member since:
    Mar 2010

    Posted 16 Dec 2019 Link to this post

    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. Daniel Blendea
    Daniel Blendea avatar
    39 posts
    Member since:
    Mar 2010

    Posted 16 Dec 2019 in reply to Daniel Blendea Link to this post

    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.)

     

  3. Martin
    Admin
    Martin avatar
    165 posts

    Posted 19 Dec 2019 Link to this post

    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.
Back to Top