我正在使用Dojo dgrid我创建了一个包含多行的网格,其中每行都有一个复选框。我想为复选框创建一个多选列。列标题应该是一个复选框,当我检查它时,所有行都会自动选中。
代码(JSFIDDLE)
function(parser, declare, OnDemandGrid, ColumnSet, Selection, selector,
Keyboard, DijitRegistry, editor, ColumnHider) {
parser.parse();
var data = [ {
Id : "1",
idType : "Passport",
idNumber : "12121545WWW"
}, {
Id : "2",
idType : "Drivers Permit",
idNumber : "11212154515 FF"
}, {
Id : "3",
idType : "Electoral Identification",
idNumber : "425123123121"
} ];
var columns = [ [ [ {
label : "Id",
field : "Id"
}, editor({
label : "",
field : "select",
sortable : false,
autoSave : true
}, "checkbox"), {
field : "idType",
label : "Identification Type"
}, {
field : "idNumber",
label : "Identification Number"
} ] ] ];
var CustomGrid = declare([ OnDemandGrid, Selection, selector, Keyboard,
editor, DijitRegistry, ColumnHider ]);
var grid = new CustomGrid({
columns : {
col1 : {
label : "Id",
field : "Id",
hidden : true
},
col2 : editor({
label : "Select",
field : "select",
sortable : false,
autosave : true
}, "checkbox"),
col3 : {
label : "ID Type",
field : "idType"
},
col4 : {
label : "ID Number",
field : "idNumber"
}
},
"class" : "grid",
allowSelectAll : true
}, "grid");
// grid.styleColumn("Id","display:none;");
grid.renderArray(data);
});
答案 0 :(得分:1)
selector
是一个应该用于生成包含您想要的列的函数。它不应该混合到网格中,而应该在列定义中使用:
columns: {
selector: selector(),
}
"全选"如果网格的selector
属性设置为allowSelectAll
,则true
会自动在标头中呈现复选框。
Here is your updated code