Ascending/descending values (prices)
Ascending/descending values (prices)
mike1985
Posts: 6Questions: 0Answers: 0
Hi there,
I'm building a table, but when I fill in values like:
15,-
21,-
170,-
600,-
65,-
the ascending/descending function gives this order:
15,-
170,-
21,-
600,-
65,-
It looks like the function looks at the first numbers and not at the total value.
Does someone know a solution for this??
I'm building a table, but when I fill in values like:
15,-
21,-
170,-
600,-
65,-
the ascending/descending function gives this order:
15,-
170,-
21,-
600,-
65,-
It looks like the function looks at the first numbers and not at the total value.
Does someone know a solution for this??
This discussion has been closed.
Replies
http://www.datatables.net/plug-ins/sorting
Matthew
Can someone tell me how to install a plugin like this? I'm using the WP-Table-Reload plugin for Wordpress, is that a problem?
Example: http://datatables.net/examples/plug-ins/sorting_sType.html
Exactly how this fits in with WordPress, I'm not sure though - not something I've used before...
Allan
How can I implement a plugin in a Wordpress-plugin?
I hope that someone can help!
Thanks
Allan
Can you tell me how you solved the problem? I am having the same issue (but not trying to integrate with Wordpress) with percentages. How were you able to solve the problem? I tried following the link but its still not working.
Sharat
[code]
jQuery.fn.dataTableExt.oSort['percent-asc'] = function(a,b) {
var x = (a == "-") ? 0 : a.replace( /%/, "" );
var y = (b == "-") ? 0 : b.replace( /%/, "" );
x = parseFloat( x );
y = parseFloat( y );
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['percent-desc'] = function(a,b) {
var x = (a == "-") ? 0 : a.replace( /%/, "" );
var y = (b == "-") ? 0 : b.replace( /%/, "" );
x = parseFloat( x );
y = parseFloat( y );
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
$(document).ready(function() {
$('#example').dataTable( {
"aoColumns": [
null,
null,
null,
{ "sType": "percent" },
null
]
} );
} );
[/code]
Thanks,
Allan
Thanks for getting back to me. The url is http://www.my5or5.com/haha.php. It's the column labeled PJ.
Sharat
[code]
jQuery.fn.dataTableExt.oSort['percent-asc'] = function(a,b) {
var x = (a == "-") ? 0 : a.replace( /<.*?>/g, "" ).replace( "%", "" );
var y = (b == "-") ? 0 : b.replace( /<.*?>/g, "" ).replace( "%", "" );
x = parseFloat( x );
y = parseFloat( y );
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['percent-desc'] = function(a,b) {
var x = (a == "-") ? 0 : a.replace( /<.*?>/g, "" ).replace( "%", "" );
var y = (b == "-") ? 0 : b.replace( /<.*?>/g, "" ).replace( "%", "" );
x = parseFloat( x );
y = parseFloat( y );
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
[/code]
That should do it.
Allan
Was also wondering if you could help me with another question I have. Where do I find the code for the search text and textbox? I ctrl-f the source code and couldn't find it.
Allan
Sharat
Allan