数据单元格编辑器是通过DataColumn.editor属性而指定的,并且基本适用于包含在相关列的所有单元格。 但是,即使是属于同一列的数据单元格,有时也会有必要分别为各个行提供不同的编辑器, 而这时,可以使用GridBase.registerCellEditors和DataColumn.editorCallback。
上述例题中,已在"进出口"列中,指定了各个行的编辑器。 首先,我们需要在网格中,注册编辑器设置信息,
grid.registerCellEditors([{
id: "text01"
}, {
id: "list01",
type: "list",
values: ["import", "export"]
}, {
id: "list02",
type: "list",
values: ["import", "export"],
labels: ["进口", "出口"]
}]);
然后,当设置列时,在editorCallback中,指定回调函数。
var columns = [{
name: "Flow",
editorCallback: function (index) {
var v = grid.getValueAt(index.rowIndex, 'trade');
if (v > 20000) {
return 'list02';
} else if (v > 10000) {
return 'list01';
} else {
return 'text01';
}
}
},
...