在 Kendo UI TreeList 中创建只读行
Make read-only rows on KendoUI TreeList
我正在制作一个 KendoUI TreeList table,我需要一些行是只读的。
由于默认情况下该选项不存在,我正在尝试按照本教程 Here 执行此操作,该教程在 KendoGrid 上效果很好,但在我的树列表上却不行。
我正在定义一个模板,它只为我标记为 "readonly" 的行创建一个编辑按钮。
按钮出现了,但当我点击它时没有任何反应...有人知道为什么吗?
这是我制作的示例:http://dojo.telerik.com/EXupO/2
感谢您的帮助!
请尝试使用以下代码片段。我已经更改了编辑模板脚本的代码。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled</title>
<link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.429/styles/kendo.common.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.429/styles/kendo.rtl.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.429/styles/kendo.default.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.429/styles/kendo.dataviz.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.429/styles/kendo.dataviz.default.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.429/styles/kendo.mobile.all.min.css">
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://cdn.kendostatic.com/2015.1.429/js/angular.min.js"></script>
<script src="http://cdn.kendostatic.com/2015.1.429/js/jszip.min.js"></script>
<script src="http://cdn.kendostatic.com/2015.1.429/js/kendo.all.min.js"></script>
</head>
<body>
<div id="example">
<div id="treelist"></div>
</div>
<script id="edit-template" type="text/x-kendo-template">
# if (!data.readonly) { #
<button data-command="edit" class="k-button k-button-icontext k-grid-edit"><span class="k-icon k-edit"></span>Edit</button>
# } #
</script>
<script>
$(document).ready(function () {
var editTemplate = kendo.template($("#edit-template").html());
var grid = $("#treelist").kendoTreeList({
dataSource: {
data: [{ DomainId: 1, Name: "Test", ReportsTo: null, readonly: true },
{ Name: "Categorie1", ReportsTo: 1, a: "10", b: "5" },
{ Name: "Categorie2", ReportsTo: 1, a: "10", b: "5" },
{ Name: "Categorie3", ReportsTo: 1, a: "10", b: "5" },
],
batch: true,
schema: {
model: {
id: "DomainID",
fields: {
parentId: { field: "ReportsTo", nullable: true, editable: false },
DomainID: { field: "DomainId", type: "number", editable: false },
Name: { validation: { required: true }, editable: false },
a: { type: "number", editable: true },
b: { type: "number", editable: true },
},
expanded: true
},
}
},
editable: true,
columns: [
{ field: "Name", title: "Domain", width: 400, editable: false },
{ field: "a", title: "1", filterable: false, sortable: false },
{ field: "b", title: "2", filterable: false, sortable: false },
{ field: "readonly", title: " ", width: 100, template: editTemplate, editor: function () { } }
],
editable: "popup",
pageable: true,
});
});
</script>
</body>
</html>
如有任何疑问,请告诉我。
我正在制作一个 KendoUI TreeList table,我需要一些行是只读的。
由于默认情况下该选项不存在,我正在尝试按照本教程 Here 执行此操作,该教程在 KendoGrid 上效果很好,但在我的树列表上却不行。
我正在定义一个模板,它只为我标记为 "readonly" 的行创建一个编辑按钮。
按钮出现了,但当我点击它时没有任何反应...有人知道为什么吗?
这是我制作的示例:http://dojo.telerik.com/EXupO/2
感谢您的帮助!
请尝试使用以下代码片段。我已经更改了编辑模板脚本的代码。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled</title>
<link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.429/styles/kendo.common.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.429/styles/kendo.rtl.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.429/styles/kendo.default.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.429/styles/kendo.dataviz.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.429/styles/kendo.dataviz.default.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.429/styles/kendo.mobile.all.min.css">
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://cdn.kendostatic.com/2015.1.429/js/angular.min.js"></script>
<script src="http://cdn.kendostatic.com/2015.1.429/js/jszip.min.js"></script>
<script src="http://cdn.kendostatic.com/2015.1.429/js/kendo.all.min.js"></script>
</head>
<body>
<div id="example">
<div id="treelist"></div>
</div>
<script id="edit-template" type="text/x-kendo-template">
# if (!data.readonly) { #
<button data-command="edit" class="k-button k-button-icontext k-grid-edit"><span class="k-icon k-edit"></span>Edit</button>
# } #
</script>
<script>
$(document).ready(function () {
var editTemplate = kendo.template($("#edit-template").html());
var grid = $("#treelist").kendoTreeList({
dataSource: {
data: [{ DomainId: 1, Name: "Test", ReportsTo: null, readonly: true },
{ Name: "Categorie1", ReportsTo: 1, a: "10", b: "5" },
{ Name: "Categorie2", ReportsTo: 1, a: "10", b: "5" },
{ Name: "Categorie3", ReportsTo: 1, a: "10", b: "5" },
],
batch: true,
schema: {
model: {
id: "DomainID",
fields: {
parentId: { field: "ReportsTo", nullable: true, editable: false },
DomainID: { field: "DomainId", type: "number", editable: false },
Name: { validation: { required: true }, editable: false },
a: { type: "number", editable: true },
b: { type: "number", editable: true },
},
expanded: true
},
}
},
editable: true,
columns: [
{ field: "Name", title: "Domain", width: 400, editable: false },
{ field: "a", title: "1", filterable: false, sortable: false },
{ field: "b", title: "2", filterable: false, sortable: false },
{ field: "readonly", title: " ", width: 100, template: editTemplate, editor: function () { } }
],
editable: "popup",
pageable: true,
});
});
</script>
</body>
</html>
如有任何疑问,请告诉我。