Using variables with fnSort

Using variables with fnSort

LesGLesG Posts: 14Questions: 0Answers: 0
edited August 2012 in General
I have a varity of custom sorts I need to implement and the logical approach is to pass variables to a sort function. The function works great with literals however not with variables. I could use a large switch statement with all the sort scenarios, but it seems like this should work.

Any ideas?

[code]
function sortTable(colSort, sortAD){
oTable.fnSort( [ [ colSort , sortAD ] ] );
}
[/code]

Replies

  • allanallan Posts: 63,541Questions: 1Answers: 10,476 Site admin
    Looks like it should work fine to me. Three assumptions:

    1. oTable is a DataTables object which the function has has the correct scope to access?
    2. colSort is an integer
    3. sortAD is 'asc' or 'desc'

    I'd suggest adding a console.log to check that these are all correct.

    Allan
  • LesGLesG Posts: 14Questions: 0Answers: 0
    Found the problem, had to lower case sortAD.

    Thanks
  • allanallan Posts: 63,541Questions: 1Answers: 10,476 Site admin
    Ah good stuff. Thanks for letting us know you got it sorted.

    Allan
This discussion has been closed.