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

Javascript select DropDownList item prolem in GRID

3 Answers 70 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Jana Vichtova
Top achievements
Rank 1
Jana Vichtova asked on 16 Oct 2015, 01:09 PM

Hello,

I have DropDownList, his data are dynamicly loaded due to Project DropDownList. In DataBound event I want change to select first value by JavaScript. I use SetDefValuesO function for this. It works, when data are loaded in Operation list function automaticly select first item. But when i click to save in inline edit Grid Row, update request do not contain changed value. It works only when ​I do it by mouse click.

 

Grid code:

   columns.Bound(work => work.Operation).ClientTemplate("#=Operation.Code#").Width(100);

.....

.Model(model =>
 {
    model.Id(p => p.Id);
    model.Field(p => p.Operation).DefaultValue(ViewData["defaultOperation"] as TT.Web.Models.ViewModel.OperationViewModel);
    model.Field(p => p.Spp).DefaultValue(ViewData["defaultSpp"] as TT.Web.Models.ViewModel.SppViewModel);
    model.Field(p => p.Project).DefaultValue(ViewData["defaultProject"] as TT.Web.Models.ViewModel.ProjectViewModel);
})

 

 Dropdown for Editor template :

 

function SetDefValuesO(){
 
 var OperationCount = $("#Operation").data("kendoDropDownList").dataSource._data.length;
 if(OperationCount == 1){
    $("#Operation").data("kendoDropDownList").select(1);
 }
}

 

Value is selected correctly, but data which are send by clicking save in inlineEdit mode, do not containt selected value, but the default value defined in GRID model (first code sample).

 

Thnaks for Help !

3 Answers, 1 is accepted

Sort by
0
Jana Vichtova
Top achievements
Rank 1
answered on 16 Oct 2015, 01:11 PM

I´m soory I forget code for EditorTemplate:

 

@(Html.Kendo().DropDownList()
    .Name("Operation")
    .OptionLabel("Vyberte výkon...")
    .CascadeFrom("Project")
    .DataValueField("Id")
    .Events(ev => ev.DataBound("SetDefValuesO") )
    .HtmlAttributes( new { requiredvalidationmessage = "required field", required = "required" })
    .DataTextField("Code")
                      .DataSource(source =>
                      {
 
                          source.Read(read =>
                          {
                              read.Action("GetCascadeOperations", "Home")
                                    .Data("filterOperations");
                          }).ServerFiltering(true);
                      })
                      .Enable(false)
                      .AutoBind(false))

0
Jana Vichtova
Top achievements
Rank 1
answered on 16 Oct 2015, 01:35 PM

Solved by:

this.trigger("change"); after select by javascript....

 

This is a bug ??​

0
Boyan Dimitrov
Telerik team
answered on 20 Oct 2015, 06:35 AM

Hello Martin Vesely,

 

This is actually expected behavior since the select method of the Kendo UI DropDownList does not trigger change event. As explained in the article  this could affect MVVM value binding. The model bound to the widget will not be updated. The model object is updated using MVVM value binding, so manually triggering the "change" event is required. 

 

Regards,
Boyan Dimitrov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
DropDownList
Asked by
Jana Vichtova
Top achievements
Rank 1
Answers by
Jana Vichtova
Top achievements
Rank 1
Boyan Dimitrov
Telerik team
Share this question
or