Get column name by index

Get column name by index

UdiDUdiD Posts: 16Questions: 7Answers: 1

Is there a way to get a column name (i.e., the name defined using columns.name option), which is more direct than the following one?

var exampleIndex = 3;
var columnName = table.settings().init().columns[exampleIndex].name;

Answers

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    i typically declare my columns separate so I can access that information, something like

    var cols = null;
    $(document).ready(function(){
    cols = [{}, {}, {}]

     $("#example").DataTable({columns:cols});
    

    })

  • allanallan Posts: 63,457Questions: 1Answers: 10,466 Site admin

    This is something that will be added in DataTables 2. There isn't an API for getting the name in 1.x I'm afraid.

    v2 won't be launching until sometime next year before you ask :). I'm not sure when - there is still a lot of work to do on it!

    Until then, I would suggest wrapping your code up into a plug-in API method.

    Allan

This discussion has been closed.