[How to] use (hidden sorting) plug-in

[How to] use (hidden sorting) plug-in

yusukeyusuke Posts: 4Questions: 0Answers: 0
edited March 2011 in Plug-ins
Hi there
I'd like to start by saying a big thanks for this script, which helped us a lot in our devs.

It's easy to implemente, and quite effective.

But I now try to use the plug-ins, and I wouldn't say the same :)

I looked the forum, tried some of the tips, but can't make the plug-in "Hidden title numeric sorting" to work

here is my code :

[code]
jQuery.fn.dataTableExt.oSort['title-numeric-asc'] = function(a,b) {
var x = a.match(/title="*(-?[0-9]+)/)[1];
var y = b.match(/title="*(-?[0-9]+)/)[1];
x = parseFloat( x );
y = parseFloat( y );
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};

jQuery.fn.dataTableExt.oSort['title-numeric-desc'] = function(a,b) {
var x = a.match(/title="*(-?[0-9]+)/)[1];
var y = b.match(/title="*(-?[0-9]+)/)[1];
x = parseFloat( x );
y = parseFloat( y );
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};

$(document).ready(
function()
{
$('.display').dataTable( {
"bPaginate": false,
"bFilter": true,
"bInfo": false,
"aoColumns": [
null,
null,
null,
null,
null,
null,
{"sType": "numeric"},
null,
null,
null,
null,
null,
null
]} );
}
);
[/code]

And one of the TDs that I want to order, as an example

443.96 Mo

problem : when I clic on the TH for "File size", nothing happens.
But the other columns work fine
Firefox 4 / WinXP

Anyone can see what I have done wrong?
I find implementing the Datatables plug-ins quite confusing, and we have very few live examples on the site.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    You need to set sType to be "title-numeric" for the column that you want to use the hidden title sorting plug-in. Documentation for how to use sorting plug-ins is here: http://datatables.net/plug-ins/sorting#how_to_type . And an example here: http://datatables.net/examples/plug-ins/sorting_sType.html .

    Allan
  • yusukeyusuke Posts: 4Questions: 0Answers: 0
    edited March 2011
    Perfect it works!
    Thanks again, and WOW for the support, that the kind of script I was happy to make a donation to and i don't regret it one bit :)

    And an idea : you could place the link to the online example directly below the description of each plug-in, or next to "Show detail"
This discussion has been closed.