MultiSelect - Setting Values on Clientside when using ServerFiltering

2 posts, 0 answers
  1. Gavin
    Gavin avatar
    4 posts
    Member since:
    Mar 2015

    Posted 08 Dec 2015 Link to this post

    Hi,

     I am using Kendo.Mvc 2015.1.408.545

    How can I use TypeScript / jQuery to set the values on a MultiSelect when Ajax and ServerFiltering are used as the DataSource?  I know the value and text as they have been saved to the database previously.  How can I set the values?  This is before user has used the MultiSelect to retrieve data using server filtering.

                          @(form.FormGroup().CustomControls(
                                Html.Kendo().MultiSelectFor(x => x.PKeys)
                                .HtmlAttributes(new { tabindex = "5" })
                                .Deferred()
                                .Name("pMultiSelect")
                                .AutoBind(false)
                                .DataTextField("Name")
                                .DataValueField("PKey")
                                .Filter(FilterType.StartsWith)
                                .MinLength(2)
                                .Placeholder("[All]")
                                .DataSource(source =>
                                {
                                    source.Read(read => read.Action("AjaxFilterSearch", "P")
                                        .Data("pMultiSelectReadData"));
                                    source.ServerFiltering(true);
                                })

                           ).LabelFor(x => x.PKeys))

    I have tried JSON, string arrays, strings, using the MultiSelect.value() will not display what is in "Name" field.

     

    Thanks very much

  2. Gavin
    Gavin avatar
    4 posts
    Member since:
    Mar 2015

    Posted 08 Dec 2015 in reply to Gavin Link to this post

    The missing step was to manually add the object to the dataSource of the MultiSelect control e.g. :

            public addSelectedP(p: ExternalModel.P.IP): void {
                if (!this.pMultiSelect)
                    return;

                this.pMultiSelect.dataSource.add(p);
                var selectedPKeys = this.pMultiSelect.value().slice();
                selectedPKeys.push(p.PKey);
                this.pMultiSelect.value(selectedPKeys);
            }

  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top