Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery datatables columnDefs target a name rather than index

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?

like image 813
Notaras Avatar asked May 20 '15 05:05

Notaras


People also ask

What is columnDefs DataTable targets?

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.

What is columnDefs in DataTable jQuery?

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.

What are the salient features of DataTables in jQuery?

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.

What is jQuery DataTables JS?

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.


1 Answers

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)
like image 86
Raidri Avatar answered Sep 18 '22 11:09

Raidri