DataTables Javascript中的默认选中复选框

时间:2018-10-02 14:05:48

标签: javascript datatables

我有以下数据表,它可以正常运行,但是是否可以将复选框的默认值设置为选中状态?

$('#example').DataTable( {
        data         : dataSet.data,
        paging       : false,
        ordering     : false,
        searching    : false,
        destroy      : true,
        select       : { style:    'os', 
                         selector: 'td:first-child'},

        columnDefs   : [ { orderable: false,
                           className: 'select-checkbox',
                           targets:   0,
                           }
        ],

        columns      : [ { data: "selected" },
                         { data: "Column1", title: "Column1" },
                         { data: "Column2", title: "Column2" },
        ]   
    });

1 个答案:

答案 0 :(得分:0)

执行“未选择”的“呈现”应该可以.....

$('#example').DataTable( {
    data         : dataSet.data,
    paging       : false,
    ordering     : false,
    searching    : false,
    destroy      : true,
    select       : { style:    'os', 
                     selector: 'td:first-child'},

    columnDefs   : [ { orderable: false,
                       className: 'select-checkbox',
                       targets:   0,
                       render: function (data, type, row){
                           return !data;
                       }
                     }
    ],

    columns      : [ { data: "selected" },
                     { data: "Column1", title: "Column1" },
                     { data: "Column2", title: "Column2" },
    ]   
});