【问题标题】:how to load view in Popup editing in kendo grid如何在剑道网格中的弹出窗口编辑中加载视图
【发布时间】:2013-06-23 21:02:29
【问题描述】:

我是 KendoUI 的初学者,我为创建网格编写此代码

 @(Html.Kendo().Grid(Model)
      .Name("Grid")
      .Columns(columns =>
                   {
                       columns.Bound(p => p.Id).Groupable(false).Visible(false);
                       columns.Bound(p => p.BrandName);
                       columns.Bound(p => p.BrandAbbr);
                       columns.Bound(p => p.SrcImage);
                       columns.Bound(item => @item.Id).Title("Command").Filterable(false).Groupable(false)
                           .Template(@<text>
                                          @Html.ActionLink("Edit", "Edit", new {id = @item.Id}, new {@class = "k-button k-button-icontext k-grid-Edit"})
                                          @Html.ActionLink("Delete", "Delete", new {id = @item.Id}, new {@class = "k-button k-button-icontext k-grid-Delete"})
                                      </text>).Width(200);
                   });
})
    .ToolBar(toolbar =>
                    {
                        toolbar.Custom().Action("Create","Brand").Text("add");                          
                    }
        )
        .Groupable()
        .Pageable()
        .Sortable()
        .Scrollable()
        .Filterable()
        .HtmlAttributes(new {style = "height:500px;"})              
        .DataSource(dataSource => dataSource
                                    .Server()                           
                                    .Model(model => model.Id(item => item.Id))
                    ))     

在这个网格中,我有删除和编辑命令。我想当用户单击编辑按钮进入网格视图编辑时以弹出形式显示。但我不知道该怎么做。请帮我。谢谢大家。

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-4 kendo-ui kendo-grid kendo-asp.net-mvc


    【解决方案1】:

    这是更好的选择 - Demo-Popup editing

    在网格的列声明部分,

    .Columns(columns =>
      columns.Command(command => { 
          command.Edit();       //for edit functionality
          command.Destroy();    //for delete functionality
      })
    .Editable(editable => editable.Mode(GridEditMode.PopUp))
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(20)
        .Events(events => events.Error("error_handler"))
        .Model(model => model.Id(p => p.Id))
        .Create(update => update.Action("EditingInline_Create", "Grid"))
        .Read(read => read.Action("EditingInline_Read", "Grid"))
        .Update(update => update.Action("EditingInline_Update", "Grid"))
        .Destroy(update => update.Action("EditingInline_Destroy", "Grid"))
    )
    

    【讨论】:

    • @Paritosh:感谢您的帮助。但是当用户单击编辑按钮时,此代码会显示编辑表单弹出窗口,但我想在弹出窗口中加载编辑视图,用户可以更新数据并保存。谢谢你的帮助。
    【解决方案2】:

    为此,您必须使用Custom commandkendoWindow(显示弹出窗口)和template(显示弹出窗口内的内容)。

    在网格中,

    columns.Command(command => command.Custom("Edit").Click("editItem"));
    

    然后(当你点击“编辑”时会发生什么......)定义窗口的模板。

    <script type="text/x-kendo-template" id="template">
        <div id="details-container"> <!-- this will be the content of the popup -->
            BrandName: <input type='text' value='#= BrandName #' />
            .....
            .....
        </div>
    </script>
    
    <script type="text/javascript">
        var detailsTemplate = kendo.template($("#template").html());
    
        function editItem(e) {
            e.preventDefault();
    
            var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
            var wnd = $("#Details").data("kendoWindow");
    
            wnd.content(detailsTemplate(dataItem));
            wnd.center().open();
        }
    </script>
    

    【讨论】:

    • 在此代码中用于编辑使用 Templete,但我想在弹出窗口中为用户加载编辑视图,感谢您的帮助。
    • 您可以使用kendo window - Loading content with AJAX在窗口中加载您的自定义视图
    • 我想使用剑道窗口,但我不知道如何创建通用剑道窗口,我在这个网址提问:stackoverflow.com/questions/17281582/…
    • @Paritosh - 这也帮助我解决了将 kendow Window 绑定到模板的问题。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-28
    • 2015-05-04
    • 1970-01-01
    • 2017-12-28
    • 1970-01-01
    相关资源
    最近更新 更多