In the kendo ui treelist the headerTemplate works for a multi-column only in the lowest column of the hierarchy. Not in the root column.
Sample:
JavaScript
x
18
18
1
columns: [{
2
field: "FirstName", title: "First Name", width: 180
3
}, {
4
title: "Personal Info",
5
/* headerTemplate: "Personal Info Template", */ /* do not works */
6
columns: [{
7
field: "LastName", title: "Last Name", width: 120,
8
}, {
9
title: "Location",
10
columns: [{
11
field: "City", width: 140,
12
headerTemplate: "City Template", /* works */
13
}, {
14
field: "Country", width: 140
15
}]
16
}]
17
}]
18
Sample Link
How can a button/html be placed in the root column of a multi-column header?
Advertisement
Answer
I’ve checked the console and it has a runtime error when that headerTemplate
was uncommented:
Uncaught TypeError: i.headerTemplate is not a function
So i suposed it was expecting a template function, like:
JavaScript
1
2
1
headerTemplate: kendo.template("Personal Info Template"),
2
And it works, hence you can use html in that template:
JavaScript
1
77
77
1
<!DOCTYPE html>
2
<html>
3
<head>
4
<base href="https://demos.telerik.com/kendo-ui/treelist/multicolumnheaders">
5
<style>html { font-size: 14px; font-family: Arial, Helvetica, sans-serif; }</style>
6
<title></title>
7
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2021.1.119/styles/kendo.bootstrap-v4.min.css" />
8
9
<script src="https://kendo.cdn.telerik.com/2021.1.119/js/jquery.min.js"></script>
10
11
12
<script src="https://kendo.cdn.telerik.com/2021.1.119/js/kendo.all.min.js"></script>
13
14
15
16
</head>
17
<body>
18
<div id="example">
19
20
<div id="treelist"></div>
21
22
<script>
23
$(document).ready(function () {
24
var service = "https://demos.telerik.com/kendo-ui/service";
25
26
$("#treelist").kendoTreeList({
27
dataSource: {
28
transport: {
29
read: {
30
url: service + "/EmployeeDirectory/All",
31
dataType: "jsonp"
32
}
33
},
34
schema: {
35
model: {
36
id: "EmployeeID",
37
parentId: "ReportsTo",
38
fields: {
39
ReportsTo: { field: "ReportsTo", nullable: true },
40
EmployeeID: { field: "EmployeeId", type: "number" },
41
Extension: { field: "Extension", type: "number" }
42
},
43
expanded: true
44
}
45
}
46
},
47
height: 540,
48
sortable: true,
49
resizable: true,
50
reorderable: true,
51
columnMenu: true,
52
columns: [{
53
field: "FirstName", title: "First Name", width: 180
54
}, {
55
title: "Personal Info",
56
headerTemplate: kendo.template("Personal Info <button>Button</button>"),
57
columns: [{
58
field: "LastName", title: "Last Name", width: 120,
59
}, {
60
title: "Location",
61
columns: [{
62
field: "City", width: 140,
63
headerTemplate: "City Template", /* works */
64
}, {
65
field: "Country", width: 140
66
}]
67
}]
68
}]
69
});
70
});
71
</script>
72
</div>
73
74
75
76
</body>
77
</html>