Passing variables into column() parameter

Passing variables into column() parameter

highflyinghighflying Posts: 9Questions: 5Answers: 0

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

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    Answer ✓

    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

  • highflyinghighflying Posts: 9Questions: 5Answers: 0

    Worked like a charm. Thanks.

This discussion has been closed.