Disable checkboxes on page load

Sometimes you may want to disable checkboxes during table initialization or enable/disable checkboxes dynamically at runtime.

This is possible with cell().checkboxes.enable() and cell().checkboxes.disable() API methods.

Preferred solution

Code shown below will work in all cases except when deferred rendering is enabled in client-side processing mode with deferRender: true option. In that case see alternative solution below.

Example

In the example below checkboxes and row selection are disabled for all employees with Software Engineer position.

Name Position Office Extn. Start date Salary
Name Position Office Extn. Start date Salary
$(document).ready(function (){
   var table = $('#example1').DataTable({
      'ajax': '/lab/jquery-datatables-checkboxes/ids-arrays.txt',
      'columnDefs': [
         {
            'targets': 0,
            'checkboxes': {
               'selectRow': true
            },
            'createdCell':  function (td, cellData, rowData, row, col){
               if(rowData[2] === 'Software Engineer'){
                  this.api().cell(td).checkboxes.disable();
               }
            }
         }
      ],
      'select': 'multi',
      'order': [[1, 'asc']]
   });
});

Alternative solution: Deferred rendering

Solution demonstrated below should be used if you enabled deferred rendering in client-side processing mode with deferRender: true option.

Example

In the example below checkboxes and row selection are disabled for all employees with Software Engineer position.

Name Position Office Extn. Start date Salary
Name Position Office Extn. Start date Salary
$(document).ready(function (){
   var table = $('#example2').DataTable({
      'ajax': '/lab/jquery-datatables-checkboxes/ids-arrays.txt',
      'initComplete': function(settings){
         var api = this.api();

         api.cells(
            api.rows(function(idx, data, node){
               return (data[2] === 'Software Engineer') ? true : false;
            }).indexes(),
            0
         ).checkboxes.disable();
      },
      'columnDefs': [
         {
            'targets': 0,
            'checkboxes': {
               'selectRow': true
            }
         }
      ],
      'deferRender': true,
      'select': 'multi',
      'order': [[1, 'asc']]
   });
});