need to get column index when column title is known

need to get column index when column title is known

umaeswaraumaeswara Posts: 72Questions: 14Answers: 0

http://live.datatables.net/toxanume/5/edit here is my testcase.
i want to know the index of the column Position; and can you please advice how can I do that.
I used jquery way of doing it but it is taking long time. so i want to use datatable apis.
thanks
Uma-

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    You are getting this error:

    Uncaught TypeError: table.column(...).header(...).text is not a function

    You need to wrap table.column( i ).header() into jQuery to get the text, like this:

    var title = $( table.column( i ).header() ).text();
    

    Updated example:
    http://live.datatables.net/gigerava/1/edit

    Another option is to use columns.name then use the column-selector of {string}:name to get the index. I added this to the example.

    Kevin

  • umaeswaraumaeswara Posts: 72Questions: 14Answers: 0

    perfect i was trying position:name method too earlier. i have copy pasted your line in my testcase and it is not working. i am so sorry but i couldnt figure out what is wrong with that line. console.log('Using Position:name', table.column("Position:name").index()); my testcase http://live.datatables.net/toxanume/5/edit

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951
    Answer ✓

    You didn't add the columns.name option in your Datatables init code.

    Kevin

  • umaeswaraumaeswara Posts: 72Questions: 14Answers: 0

    Hi kevin,
    i have 60 columns, can I use any render function to initiate columns.name ? like get the name of the column, and init name for each of the columns.
    thanks,
    Uma-

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951
    Answer ✓

    You have to define columns.name a initialization. You can create a variable that contains your columns definition before initialization then use that variable in the init code, for example:

    http://live.datatables.net/gigerava/3/edit

    Kevin

Sign In or Register to comment.