How to sort using a hidden column in 1.10.0
How to sort using a hidden column in 1.10.0
Hi,
I am upgrading from 1.9.4 to 1.10.2 and having trouble finding out how to convert a 1.9.4 initialisation that uses a hidden column to sort another (for subnet addresses that need converted to integers to be sorted).
My 1.9.4 initialisation was
$('table.subnets').dataTable({
"aoColumns": [
{ "bSortable": true, "sType": "numeric", "iDataSort": 1 },
{ "bSortable": true, "bSearchable": false, "bVisible": false },
{ "bSortable": true },
{ "bSortable": true },
{ "bSortable": true },
{ "bSortable": true }
]
});
I'm not sure if that was 100% correct as the syntax always confused me but basically the first column of my table is the address (string) and the second column was the hidden one with the integer value which was used to sort the first column and then there were 4 other columns.
Here's my attempt at the 1.10 equivalent but not it doesn't seem to have any effect on the first column being sorted as a string (no errors):
var table = $('table.subnets');
var oTable = table.DataTable({
'columnDefs': [
{ 'sortable': true, 'searchable': false, 'visible': false, 'type': 'num', 'targets': [1] }
],
});
It's probably something silly but I can't seem to figure it out after looking through the docs.
Any help appreciated.
Martin
This question has accepted answers - jump to:
Answers
I've went back to my previous initialisation (thank goodness for backwards compatibility) but if even knows the 1.10 equivalent please let me know.
Martin
This works for me in column definitions:
Thanks @tangerine but that doesn't seem to work for me, does this look correct to you?
That looks ok to me. Are you seeing any errors other than apparent failure to sort as required?
EDIT: I should have mentioned I have this version:
//cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js
Nope, no errors on the console.
I'm using 1.10.2 at the moment but honestly don't know if that would make a difference here or not, thanks for your help anyway though.
AFAIK "orderData" has been around starting with 1.10.0 so I'm stuck now.
Perhaps Allan will have some ideas.
I was just about to post the code when I realised/remembered that the datatables column indexes start at
0
, so switched my code to use0
and1
instead of1
and2
and it works, sorry I didn't catch that before!Thanks again for your help.
I should note that I've just committed a fix for
columns.orderData
whereby it didn't work if given as an integer... The work around was to use it as an array, or use the oldiDataSort
option which was correctly converted.Allan