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

Dynamic MultiSelect in Scheduler edit Template

1 Answer 148 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Ruairi
Top achievements
Rank 1
Ruairi asked on 22 Mar 2016, 07:13 PM

Ive a scheduler with a custom editor template. The template displays a MultiSelect whose selectable values will differ depending upon what specific event is picked. So when I click an event I capture the Edit event and I refresh the MultiSelect to populate its selecteble values and this works.

 

$('#PrerequisiteOids').data('kendoMultiSelect').dataSource.read();

 

However my selected values from my model are never set in the control. I'm guessing this is something to do with it being in a Template - how do I bind my values from the selected Event?

The MultiSelect in the Template looks like this:

@(Html.Kendo().MultiSelectFor(model => model.Prerequisites)
  .Name("Prerequisites")
  .AutoBind(true)
  .DataTextField("Title")
  .DataValueField("Oid")
  .DataSource(source =>
  {
    source.Read(read =>
    {
    read.Action("GetPrerequisites", "CourseCalendar").Data("getCourseEventID");
    })
  .ServerFiltering(true);
  })
  .HtmlAttributes(new { @class = "universalWidth" }))

 

Has 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Ruairi
Top achievements
Rank 1
answered on 23 Mar 2016, 12:47 PM

This problem has been solved. The issue related to how the data was being bound to the MultiSelectFor component. In the Html.Kendo().Scheduler .Edit() event I was setting the Guid of the selected calendar item in a hidden field then calling the dataSource.read() for the MultiSelectFor component manually.

This triggered the read.Action which called the getCourseEventID JavaScript function to return the Guid from the hidden field. As the .Edit() event is raised after the MultiSelectFor is initialised, the selected values from my model were never being set in the control.

I got around this by passing in the CourseEventId directly as part of the DataSource read action which is binding automatically. I’m no longer using Edit() event.

 

@(Html.Kendo().MultiSelect()
  .Name("Prerequisites")
  .Value(Model.Prerequisites)
  .DataTextField("Title")
  .DataValueField("Oid")
  .DataSource(source =>
  {
    source.Read(read =>
    {
      read.Action("GetPrerequisites", "CourseCalendar", new { @courseEventOid = "#: CourseEventOid #" });
    })
  .ServerFiltering(true);
  })
  .HtmlAttributes(new { @class = "universalWidth" }))
Tags
Scheduler
Asked by
Ruairi
Top achievements
Rank 1
Answers by
Ruairi
Top achievements
Rank 1
Share this question
or