Dojo数据网格添加多选列

时间:2014-03-16 14:03:58

标签: javascript dojo dojox.grid.datagrid dgrid

我正在使用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);
});

1 个答案:

答案 0 :(得分:1)

selector是一个应该用于生成包含您想要的列的函数。它不应该混合到网格中,而应该在列定义中使用:

columns: { selector: selector(), }

"全选"如果网格的selector属性设置为allowSelectAll,则true会自动在标头中呈现复选框。 Here is your updated code