我创建了一个通用的 js DataGrid 创建器,代码如下:
function createGrid(targetDiv, mycolums, source, fnChange) {
return $(targetDiv).kendoGrid({
dataSource: {
data: source,
pageSize: 20
},
scrollable: true,
sortable: true,
pageable: {
input: true,
numeric: false
},
columns: mycolums,
change: fnChange
});
}
调用它:
createGrid("#grid1", columns, dataSource, onChange);
它工作正常,但我想以某种方式修改我的创建网格函数,因为有时某些网格需要绑定(bind)到其他事件,如 edit : fnEdit
等。
My Question is that, how can I modify the
createGrid
to accept objects instead of specific parameters. let say I want to make it some-thing like:
function createGrid(targetDiv, mycolums, source, OtherAttributes) {
return $(targetDiv).kendoGrid({
dataSource: {
data: source,
pageSize: 20
},
scrollable: true,
columns: mycolums,
OtherAttributes
});
所以我可以这样调用它:
createGrid("#grid1", columns, dataSource, {change: OnChange, edit: OnEdit});
最佳答案
您的建议应该可以正常工作。在您的函数中,只需在设置网格属性时检查对象属性:
var otherAttrs = {
change: onChange,
dataBound: onDatabound
};
createGrid(div, cols, datas, otherAttrs);
function createGrid(targetDiv, mycolums, source, opts) {
return $(targetDiv).kendoGrid({
dataSource: {
data: source,
pageSize: 20
},
scrollable: true,
sortable: true,
selectable: "multiple, row",
pageable: {
input: true,
numeric: false
},
columns: mycolums,
change: opts.change ? opts.change : null,
dataBound: opts.dataBound ? opts.dataBound : null,
});
Working DEMO
关于javascript - Kendo - 插入事件属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33686281/