1

在 kendo ui 树列表中,headerTemplate 仅在层次结构的最低列中适用于多列。不在根列中。

样本:

columns: [{
  field: "FirstName", title: "First Name", width: 180
  }, {
    title: "Personal Info",
    /*   headerTemplate: "Personal Info Template", */ /* do not works */
      columns: [{
        field: "LastName", title: "Last Name", width: 120,
          }, {
           title: "Location",
           columns: [{
              field: "City", width: 140, 
              headerTemplate: "City Template",      /* works */
            }, {
              field: "Country", width: 140
           }]
       }]
   }]

示例链接

如何将按钮/html 放置在多列标题的根列中?

4

1 回答 1

1

我检查了控制台,它在headerTemplate未注释时出现运行时错误:

未捕获的类型错误:i.headerTemplate 不是函数

所以我想它期待一个模板函数,比如:

headerTemplate: kendo.template("Personal Info Template"), 

它有效,因此您可以在该模板中使用 html:

<!DOCTYPE html>
<html>
<head>
    <base href="https://demos.telerik.com/kendo-ui/treelist/multicolumnheaders">
    <style>html { font-size: 14px; font-family: Arial, Helvetica, sans-serif; }</style>
    <title></title>
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2021.1.119/styles/kendo.bootstrap-v4.min.css" />

    <script src="https://kendo.cdn.telerik.com/2021.1.119/js/jquery.min.js"></script>
    
    
    <script src="https://kendo.cdn.telerik.com/2021.1.119/js/kendo.all.min.js"></script>
    
    

</head>
<body>
    <div id="example">

    <div id="treelist"></div>

    <script>
        $(document).ready(function () {
            var service = "https://demos.telerik.com/kendo-ui/service";

            $("#treelist").kendoTreeList({
                dataSource: {
                    transport: {
                        read: {
                            url: service + "/EmployeeDirectory/All",
                            dataType: "jsonp"
                        }
                    },
                    schema: {
                        model: {
                            id: "EmployeeID",
                            parentId: "ReportsTo",
                            fields: {
                                ReportsTo: { field: "ReportsTo", nullable: true },
                                EmployeeID: { field: "EmployeeId", type: "number" },
                                Extension: { field: "Extension", type: "number" }
                            },
                            expanded: true
                        }
                    }
                },
                height: 540,
                sortable: true,
                resizable: true,
                reorderable: true,
                columnMenu: true,
                columns: [{
                    field: "FirstName", title: "First Name", width: 180
                }, {
                    title: "Personal Info",
                    headerTemplate: kendo.template("Personal Info <button>Button</button>"), 
                    columns: [{
                        field: "LastName", title: "Last Name", width: 120,
                    }, {
                        title: "Location",
                        columns: [{
                            field: "City", width: 140, 
                            headerTemplate: "City Template",        /* works */
                        }, {
                            field: "Country", width: 140
                        }]
                    }]
                }]
            });
        });
    </script>
</div>

    

</body>
</html>

更新道场

于 2021-02-08T16:57:49.437 回答