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

MultiSelect - Setting Values on Clientside when using ServerFiltering

1 Answer 109 Views
MultiSelect
This is a migrated thread and some comments may be shown as answers.
Gavin
Top achievements
Rank 1
Gavin asked on 08 Dec 2015, 12:46 PM

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

1 Answer, 1 is accepted

Sort by
0
Gavin
Top achievements
Rank 1
answered on 08 Dec 2015, 04:21 PM

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);
        }

Tags
MultiSelect
Asked by
Gavin
Top achievements
Rank 1
Answers by
Gavin
Top achievements
Rank 1
Share this question
or