How to install Natural Sorting?
How to install Natural Sorting?
Hello, I am using DataTables on my Wordpress blog to make my table sortable. I tried to use WP-Table Reloaded (Wordpress Plugin) to make this function but it doesn't worked because some error with my Wordpress Theme. I installed DataTables succesfuly but I need a better sorting options so I discovered Natural Sorting. I think I am doing something wrong because it doesn't work.
Here is what I had put in my header:
[code] <!-- DataTables -->
@import "../media/css/demo_page.css";
@import "../media/css/demo_table.css";
$(document).ready(function() {
$('#example').dataTable();
} );
<!-- DataTables -->
<!-- NaturalSort -->
jQuery.fn.dataTableExt.oSort['natural-asc'] = function(a,b) {
return naturalSort(a,b);
};
jQuery.fn.dataTableExt.oSort['natural-desc'] = function(a,b) {
return naturalSort(a,b) * -1;
};
<!-- NaturalSort -->[/code]
I think I also need to put the class in my table but I don't know where to get the class name and where to put in my table. I need my entire table to be using Natural Sorting.
What am I doing wrong?
Here is what I had put in my header:
[code] <!-- DataTables -->
@import "../media/css/demo_page.css";
@import "../media/css/demo_table.css";
$(document).ready(function() {
$('#example').dataTable();
} );
<!-- DataTables -->
<!-- NaturalSort -->
jQuery.fn.dataTableExt.oSort['natural-asc'] = function(a,b) {
return naturalSort(a,b);
};
jQuery.fn.dataTableExt.oSort['natural-desc'] = function(a,b) {
return naturalSort(a,b) * -1;
};
<!-- NaturalSort -->[/code]
I think I also need to put the class in my table but I don't know where to get the class name and where to put in my table. I need my entire table to be using Natural Sorting.
What am I doing wrong?
This discussion has been closed.
Replies
Allan
I am having this: US$10.90 < US$11.50 < US$5.00 < US$6.00
But I need this: US$5.00 < US$6.00 < US$10.90 < US$11.50
Here is my code:
[code] <!-- NaturalSort -->
jQuery.fn.dataTableExt.oSort['natural-asc'] = function(a,b) {
return naturalSort(a,b);
};
jQuery.fn.dataTableExt.oSort['natural-desc'] = function(a,b) {
return naturalSort(a,b) * -1;
};
<!-- NaturalSort -->
<!-- DataTables -->
@import "../media/css/demo_page.css";
@import "../media/css/demo_table.css";
$(document).ready(function() {
$('#example').dataTable( {
"aoColumnsDefs": [
null,
null,
null,
null,
null,
null,
{ "sType": "natural-desc" },
]
} );
} );
<!-- DataTables -->[/code]
*Instead of aoColumns I changed to aoColumnsDefs because reading the manual aTargets requests the last one.
Allan