Javascript select DropDownList item prolem in GRID

4 posts, 0 answers
  1. Martin Vesely
    Martin Vesely avatar
    10 posts
    Member since:
    May 2009

    Posted 16 Oct 2015 Link to this post

    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 !

  2. Martin Vesely
    Martin Vesely avatar
    10 posts
    Member since:
    May 2009

    Posted 16 Oct 2015 in reply to Martin Vesely Link to this post

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

  3. Kendo UI is VS 2017 Ready
  4. Martin Vesely
    Martin Vesely avatar
    10 posts
    Member since:
    May 2009

    Posted 16 Oct 2015 in reply to Martin Vesely Link to this post

    Solved by:

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

     

    This is a bug ??​

  5. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 20 Oct 2015 Link to this post

    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!
     
Back to Top
Kendo UI is VS 2017 Ready