Cant sort a column with custom type

Cant sort a column with custom type

CarnyCarny Posts: 3Questions: 0Answers: 0
edited April 2013 in Bug reports
Hi,

im trying to add datatables to the table on http://www.kickwelt.de/infos.phtml?cat=1&d1=7&d3=2

The last three columns have a specific numeric format (dots as thousand seperators and commas as decimal seperatos). To sort them i used the "Commas for decimal place"-sorting plugin and modified it to replace all dots with "":

[code]jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"numeric-comma-pre": function ( a ) {
var x = (a == "-") ? 0 : (a.replace( /./g, "" )).replace( /,/, "." );
return parseFloat( x );
},

"numeric-comma-asc": function ( a, b ) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},

"numeric-comma-desc": function ( a, b ) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
} );][/code]

But when im trying to sort this columns, it does nothing.

Here is the link to the debugger:

http://debug.datatables.net/oretew

If im getting it right the type "numeric-comma" doesnt exist, does it?

How can i fix this?

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Hi,

    It looks like you are loading the plug-in, before you are loading DataTables. This is causing a Javascript error, since the plug-in can't attach itself to DataTables (which hasn't been loaded).

    Javascript execution is in the same sequence as it is loaded, so you'd modify the following:

    [code]



    [/code]

    to be:

    [code]



    [/code]

    i.e.:

    1. Load DataTables
    2. Load the plug-in
    3. Use DataTables and the plug-in

    The other thing I would say is that datatables.net is not a CDN. I'd strongly recommend not loading your script from datatables.net. I will likely throttle access to the server on this server in future for hot links, since it impacts bandwidth and is this server is not suitable for use as a CDN. You'll get much better performance hosting it yourself, or using the Microsoft CDN which has DataTables on it.

    Regards,
    Allan
  • CarnyCarny Posts: 3Questions: 0Answers: 0
    Hi Allan,

    thank you for your fast help. I changed the sequence now and changed hotlinking.

    According to http://debug.datatables.net/uqaxop the last three columns are now from the type "numeric-comma", but if i click on a column it doesnt sort. Instead it does nothing.

    Is there someting wrong with the sorting-function? As i mentioned in my first post i made some custom changes on line 3 in order to sort numbers with dots as thousend seperator and commas as decimal seperator.

    Kind regards,
    Timo
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Hi Timo,

    This looks a bit suspect to me:

    > a.replace(/./g, "")

    The problem with that is that `.` means match every character (except \n) in regex. I think you want:

    > a.replace(/\./g, "")

    i.e. escape it.

    Allan
  • CarnyCarny Posts: 3Questions: 0Answers: 0
    It works :)

    Thank you!

    Timo
This discussion has been closed.