我需要向我的 kendo-grid
添加自定义工具栏
命令
,因此我搜索了kendo-ui
> 关于 grid#configuration-toolbar
的文档我在哪里发现:
If an Array value is assigned (to a toolbar property), it will be treated as the list of commands displayed in the grid's Toolbar. Commands can be custom or built-in ("cancel", "create", "save", "excel", "pdf").
我为我的工具栏创建了一个自定义命令(也在这个问题 Adding custom button to KendoGrid Toolbar Issue 中建议)
toolbar: [
{
name: "copyRows",
text: "Copy Rows",
click: function (e) {
alert('test');
}
},
],
具有单击事件处理程序的附加属性,如命令文档 columns.command.click Function 中所述:
The JavaScript function executed when the user clicks the command button. The function receives a jQuery Event as an argument.
...但是它不会触发单击事件,并且警报不会显示。
你知道我在这里缺少什么吗?
我测试的完整代码如下所示:
$("#grid").kendoGrid({
columns: [{
field: "name"
}, ],
editable: true,
toolbar: [{
name: "create",
text: "New Row"
}, {
name: "copyRows",
text: "Copy Rows",
click: function (e) {
alert('test');
}
}, ],
dataSource: {
data: [{
name: "Jane Doe"
}],
}
});
最佳答案
我已经找到解决办法了。由于一些奇怪的未记录的原因,toobar 命令与 column 命令不是同一命令,并且不能以相同的方式进行自定义。它们唯一的共同点是工具栏命令可以调用列命令。工具栏中好像没有点击事件:
$("#grid").kendoGrid({
columns: [{
field: "name"
},{
command: [{
name: "customCommand",
text: "Column Command",
click: function(e){
alert('Column Command');
}
}]
} ],
editable: true,
toolbar: [{
name: "create",
text: "New Row"
}, {
// This actually calls the column command with the same name.
name: "customCommand",
text: "Toolbar Command",
// The click event never gets fired.
click: function (e) {
alert('Toolbar Command');
}
}, ],
dataSource: {
data: [{
name: "Jane Doe"
}],
}
});
但我不想在每一行中都有一个额外的按钮,只是为了使工具栏命令起作用,因此解决方案是使用带有自定义事件处理程序的工具栏自定义模板:
$("#grid").kendoGrid({
columns: [{
field: "name"
}],
editable: true,
toolbar: [{
template:
'<a class="k-button k-button-icontext k-grid-add" href="\\#"><span class="k-icon k-add"></span>New Row</a>' +
'<a class="k-button k-grid-custom-command" href="\\#">Toolbar Command</a>'
}],
dataSource: {
data: [{
name: "Jane Doe"
}],
}
});
$('a.k-grid-custom-command').click(function (e) {
alert('Toolbar Command');
});
关于jquery - 我还需要什么才能使剑道网格自定义工具栏命令正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28024189/