Accessing other column data in custom sort function
Accessing other column data in custom sort function
alhenderson
Posts: 9Questions: 0Answers: 0
Morning All,
I have a table containing 3 columns, 1 hidden, 1 plain text and 1 containing some complex HTML. When the user sorts the HTML column I want to use a custom sort method. I have added:
jQuery.fn.dataTableExt.oSort['groups-by-alarm-desc'] = function(group1, group2) {...}
to my code and set the appropriate type in the column information. In my sort function, however, I need to get at the ID of the group objects being sorted so I can go to my JS objects to perform the sorting. I'd rather not try and parse the group1 and group2 strings that are passed to the function to get them out. I'd like to get the ID from my hidden column and use that to access my objects. I can't seem to get at any row context information in the sort function, though.
Is it possible in my sort function to find out which two rows the two strings I have been passed represent?
Thanks for any thoughts,
Al.
I have a table containing 3 columns, 1 hidden, 1 plain text and 1 containing some complex HTML. When the user sorts the HTML column I want to use a custom sort method. I have added:
jQuery.fn.dataTableExt.oSort['groups-by-alarm-desc'] = function(group1, group2) {...}
to my code and set the appropriate type in the column information. In my sort function, however, I need to get at the ID of the group objects being sorted so I can go to my JS objects to perform the sorting. I'd rather not try and parse the group1 and group2 strings that are passed to the function to get them out. I'd like to get the ID from my hidden column and use that to access my objects. I can't seem to get at any row context information in the sort function, though.
Is it possible in my sort function to find out which two rows the two strings I have been passed represent?
Thanks for any thoughts,
Al.
This discussion has been closed.
Replies
it's possible to do this using DOM data source sorting ( http://datatables.net/development/sorting#data_source ) but not with the standard sorting methods. Are you note the sorting functions just get two parameters, the two variables to check - this is effectively due to the limitations of the Array.sort() built-in function. DOM sorting allows you to overcome this by doing something like this: http://datatables.net/examples/plug-ins/dom_sort.html , although it is a little bit more expensive in terms of CPU cycles...
Allan
Thanks for your response, I'll give the DOM data sorting a go. I just wanted to make sure I wasn't missing a more elegant solution as is so often the case with these things :-)
Cheers,
Al.