Passing variables into column() parameter
Passing variables into column() parameter
Hi all,
I'm trying to do an order on a column selected by the user. Essentially my variable (columnsort) is the column index number. Here's where I'm stuck. I'm able to get oTable.column('0').order('desc').draw() to work but when I pass the variable in, the sort doesn't work. I've tried two different methods.
Method one: concatenating columnsort with the quotes within the column parameter .
var oTable = $('#dailytable').DataTable();
oTable.column("'"+columnsort+"'").order('desc').draw();
Method two: concentating the quotes outside the order string and then pass the variable in.
var columnsort= "'"+i+"'";
var oTable = $('#dailytable').DataTable();
oTable.column(columnsort).order('desc').draw();
Any idea I'm doing wrong?
This question has an accepted answers - jump to answer
Answers
Don't pass it in as a string if it is an index. Try
column( columnsort*1 )...
to make sure you are passing in an integer.Allan
Worked like a charm. Thanks.