【问题标题】:Telerik Kendo Grid editing inline with kendo treeview editor templateTelerik Kendo Grid 使用 kendo 树视图编辑器模板进行内联编辑
【发布时间】:2017-05-18 15:05:03
【问题描述】:

我有一个内联编辑的剑道网格。应该编辑其中一个字段,从列表中选择一个元素,但列表必须具有层次结构(如果能够过滤该列表会很好)。我正在考虑使用剑道树视图作为该领域的编辑器,但我还没有找到任何方法来实现这一点。我尝试制作一个呈现树视图的自定义编辑器模板(使用columns.Bound(s => s.FieldId).EditorTemplateName("_TreeEditorTemplate")),但树视图不是输入且不可选择。我还想制作一个使用剑道下拉列表的编辑器,里面有树,但这是no currently supported by kendo。有什么想法???

【问题讨论】:

    标签: c# asp.net-mvc kendo-ui kendo-grid


    【解决方案1】:

    你看过剑道网站上的样本吗:https://docs.telerik.com/kendo-ui/controls/data-management/grid/how-to/Editing/use-treeview-as-grid-editor

     <div id="example">
            <div id="grid"></div>
    
            <script>
                $(document).ready(function () {
                    var crudServiceBaseUrl = "//demos.telerik.com/kendo-ui/service",
                        dataSource = new kendo.data.DataSource({
                            transport: {
                                read: {
                                    url: crudServiceBaseUrl + "/Products",
                                    dataType: "jsonp"
                                },
                                update: {
                                    url: crudServiceBaseUrl + "/Products/Update",
                                    dataType: "jsonp"
                                },
                                destroy: {
                                    url: crudServiceBaseUrl + "/Products/Destroy",
                                    dataType: "jsonp"
                                },
                                create: {
                                    url: crudServiceBaseUrl + "/Products/Create",
                                    dataType: "jsonp"
                                },
                                parameterMap: function (options, operation) {
                                    if (operation !== "read" && options.models) {
                                        return { models: kendo.stringify(options.models) };
                                    }
                                }
                            },
                            batch: true,
                            pageSize: 20,
                            schema: {
                                model: {
                                    id: "ProductID",
                                    fields: {
                                        ProductID: { editable: false, nullable: true },
                                        ProductName: { validation: { required: true } },
                                        UnitPrice: { type: "number", validation: { required: true, min: 1 } },
                                        Discontinued: { type: "boolean" },
                                        UnitsInStock: { type: "number", validation: { min: 0, required: true } }
                                    },
                                }
                            }
                        });
    
                    $("#grid").kendoGrid({
                        dataSource: dataSource,
                        edit: function (e) {
                            //checking if a cell from the Test column is opened for editing
                            var dummyInput = e.container.find("input[name='test']");
                            if (dummyInput.length > 0) {
                                var treeView = $(e.container).find(".treeViewEditor").data("kendoTreeView");
                                var originalItem = treeView.findByText(dummyInput.val());
                                if (originalItem != null) {
                                    // Select the item based on the field value
                                    treeView.select(originalItem);
                                }
                            }
                        },
                        navigatable: true,
                        pageable: true,
                        height: 550,
                        toolbar: ["create", "save", "cancel"],
                        columns: [
                            "ProductName",
                            {
                                field: "test", title: "Test", width: 120,
                                editor: function (container, options) {
                                    var input = $("<input class='tveInput'/>");
                                    input.attr("name", options.field);
                                    var tvDiv = $("<div class='treeViewEditor'></div>");
                                    $(tvDiv).kendoTreeView({
                                        animation: false,
                                        dataSource: [
                                          {
                                            text: "foo1"
                                          },
                                          {
                                            text: "foo2",
                                            items: [
                                                { text: "bar" },
                                                { text: "bar1" },
                                                { text: "bar2" }
                                            ]
                                          }
                                        ]
                                    });
                                    var treeView = $(tvDiv).data("kendoTreeView");
                                    $(tvDiv).find(".k-in").mousedown(function (e) {
                                        var clickedNode = $(e.toElement).closest("[role=treeitem]");
                                        var dataItem = treeView.dataItem(clickedNode);
                                        var dummyInput = clickedNode.closest("[role=gridcell]").find("input[name='test']");
                                        dummyInput.val(dataItem.text);
                                        dummyInput.trigger("change");
                                    });
    
                                    tvDiv.appendTo(container);
                                    input.appendTo(container);
                                }
                            },
                            { field: "UnitPrice", title: "Unit Price", format: "{0:c}", width: 120 },
                            { field: "UnitsInStock", title: "Units In Stock", width: 120 },
                            { field: "Discontinued", width: 120 },
                            { command: "destroy", title: "&nbsp;", width: 150 }],
                        editable: true
                    });
                });
            </script>
        </div>
    
        <style>
            .tveInput {
                display: none;
            }
      </style>
    

    【讨论】:

      猜你喜欢
      • 2016-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多