15

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?

1
  • You are using a JSON datasource? How does your columns looks like? Commented May 20, 2015 at 6:51

1 Answer 1

24

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)
Sign up to request clarification or add additional context in comments.

2 Comments

targets with class name doesn't work, detail here: datatables.net/forums/discussion/26357/…
seems to be fixed. i just used it. header in html, ie <th class='col-name'> and then using it in the options: columnDefs: [ { targets: "col-name", visible: false }].

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.