簡體   English   中英

Teleken Kendo Grid與Kendo Treeview編輯器模板的內聯編輯

[英]Telerik Kendo Grid editing inline with kendo treeview editor template

我有一個內聯編輯的劍道網格。 應該對字段之一進行編輯,以從列表中選擇一個元素,但是該列表必須具有層次結構(最好能夠過濾該列表)。 我當時在考慮使用劍道樹視圖作為該字段的編輯器,但是我還沒有找到實現此目的的任何方法。 我嘗試制作一個自定義編輯器模板(使用columns.Bound(s => s.FieldId).EditorTemplateName("_TreeEditorTemplate") )來呈現樹視圖,但是樹視圖不是輸入,並且是不可選擇的。 我還考慮過使用kendo dropdownlist並在其中包含樹的編輯器,但是kendo當前不支持此編輯器。 有任何想法嗎???

您是否在Kendo網站上查看了示例: 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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM