{hero}

columnDefs.targets

Since: DataTables 1.10

Assign a column definition to one or more columns.

Description

The columnDefs option allows a column definition object to be defined and then assigned to one or more columns in a DataTable, regardless of the order of the column definitions array, or the order of the columns in the table.

This columnDefs.targets option provides the information required by DataTables for which columns in the table the column definition object should be applied.

It can be:

  • 0 or a positive integer - column index counting from the left
  • A negative integer - column index counting from the right
  • A string - class name will be matched on the TH for the column (without a leading .)
  • The string "_all" - all columns (i.e. assign a default)

Additionally, targets can be either a single option from the list above, or an array of options (the different types can be mixed in the array if required). For example targets: [ -1, -2 ] would target the last and second last columns in the table.

Please note that unlike all other column configuration options which can be applied to be columns and columnDefs, the columnDefs.targets option can only be used in columnDefs.

Type

This option can be given in the following type(s):

Examples

Disable filtering on the first column:

$('#example').dataTable( {
  "columnDefs": [ {
      "targets": 0,
      "searchable": false
    } ]
} );

Disable sorting on the first and third columns:

$('#example').dataTable( {
  "columnDefs": [ {
      "targets": [ 0, 2 ],
      "orderable": false
    } ]
} );

Disable ordering on columns which have a class of 'nosort':

$('#example').dataTable( {
  "columnDefs": [ {
      "targets": 'nosort',
      "orderable": false
    } ]
} );

Related

The following options are directly related and may also be useful in your application development.