In this code:
$('#example').dataTable( {
"columnDefs": [ {
"targets": 0,
"searchable": false
} ]
} );
targets has been given a column index. But in my case, columns can be in varying orders. So my question is, can "targets" be given the name of the column parameter and if so, how?
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.
As columnDefs allows columns to be defined one or more times in different column definition objects (typically to define different aspects of the columns) conflicts can arise whereby a single property might be defined with different values for the same column.
DataTables will read all of the information about the table from the page (the DOM) and add features such as filtering, paging and sorting. This follows the basis for progressive enhancement where a table will be enhanced if JavaScript is available, and not if the browser doesn't have the required capabilities.
jQuery DataTable is a powerful and smart HTML table enhancing plugin provided by jQuery JavaScript library. It is a highly flexible tool that is basically created to display information in tables as well as adding interactions to them, hence, enhancing data accessibility in HTML tables.
From the documentation (emphasis mine):
This
targets
property tells DataTables which column(s) the definition should be applied to. 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
- The string "_all" - all columns (i.e. assign a default)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With