Problems sorting data with decimals in it?
Problems sorting data with decimals in it?
Hi
I'm using datatables alot at a site of mine and I have a small issue with it
First of all browse to this site:
http://www.oemautomatic.se/264031-320933.html
Login top right corner with user: datatables and password datatables.
When the site is loaded you will notice a green button saying "Best
I'm using datatables alot at a site of mine and I have a small issue with it
First of all browse to this site:
http://www.oemautomatic.se/264031-320933.html
Login top right corner with user: datatables and password datatables.
When the site is loaded you will notice a green button saying "Best
This discussion has been closed.
Replies
http://www.oemautomatic.se/jquery/jquery.dataTables.js
So its loaded before the datatable which is in:
http://www.oemautomatic.se/jquery/jquery.wipcore.js
[code]{ "sSortDataType": "dom-text", "sType": "numeric-comma" },[/code]
so try to copy paste this code in your js and see how its going now
[code]
jQuery.fn.dataTableExt.oSort['numeric-comma-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['numeric-comma-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));
};
[/code]
and see this for more info http://www.datatables.net/plug-ins/sorting#numeric_comma
Or does it need to be in separate file?
What you've done is just fine, with the inclusion of the plug-in. However I think the initialisation is slightly off. Try this:
[code]
oTable = $('#bestallning').dataTable({
"bJQueryUI": true,
"bPaginate": false,
"bLengthChange": true,
"bFilter": false,
"bSort": true,
"bInfo": false,
"bAutoWidth": false,
"sScrollY": "300px",
"aoColumns": [
null,
null,
{ "sType": "numeric-comma" },
{ "sType": "numeric-comma" },
{ "sSortDataType": "dom-text", "sType": "numeric-comma" }
]
});
[/code]
You only need to use 'sSortDataType' when you are getting data from a special source - like a DOM node.
Allan
Unfortunatly that didnt work :/ Im wondering if there is anything conflictingjavascript or something like that.
By the total 5 columns there is a special hidden column we use for putting out error notices in if something goes wrong. That one does not have a header, might that be something? Also ni each of them there is a hidden input and one of them is visible.
Any more ideas would make me greatful =)
So do you actually have 6 columns in the table? To have a hidden column in the table, use bVisible - the number of columns in aoColumns must exactly match what is in the HTML.
I just add a look but the "Best