How to update Kendo Grid row from window

后端 未结 3 1557
予麋鹿
予麋鹿 2020-12-18 05:14

The set-up:

  • ASP MVC project
  • Kendo Grid in a view via Razor
  • Column custom command, calls...
  • JavaScript that opens Kendo window with r
3条回答
  •  爱一瞬间的悲伤
    2020-12-18 05:45

    Using your method you are doing double request so my suggesting: On edit open a window binded to row via MVVM :

    function edit(e) {
        //get the row which belongs to clicked edit button
        var item = this.dataItem($(e.currentTarget).closest("tr"));
    
        //bind the window to the item via mvvm http://docs.telerik.com/kendo-ui/framework/mvvm/overview 
        kendo.bind($("#window"), item);
    }
    

    The window contain an editor template (Shared/EditorTemplates/Client.cshtml) :

    @(Html.Kendo().Window().Name("window")
        .Title("Client Details")
        .Visible(false)
        .Modal(true)
        .Draggable(true)
        .Width(400)
        .Content(@
            @Html.Partial("EditorTemplates/Client", new Product())
        ))
    
    //Put in every element in the window data-bind="value:INPUT NAME" 
    // become 
    $("#window [name]").each(function () {
         var name = $(this).attr("name")
         $(this).attr("data-bind", "value:" + name );
     });
    

    The editor template :

    @model Product
    @Html.TextBoxFor(m => m.Name)
    

提交回复
热议问题