2nd order custom function

2nd order custom function

spicywebspicyweb Posts: 3Questions: 1Answers: 0
edited August 2014 in Free community support

Hi

On this site, http://billigste-internet.dk, I want to be able to make the column "DOWNLOAD", order by numeric values, when I set it to be the secondary order column.

I've succeeded in setting it up like this

"aoColumns": [
{"sType": null , orderData: [ 0, 2 ]},
{"sType": "simple-price"},
{"sType": "internet-speed"},
{"sType": "internet-speed"},
{"sType": "subscription-length"},
{"sType": "simple-price"},
{ "bSortable": false }
],

but that way, it sorts the download column, alphanumeric. As you can see, the column, when sorting primarily by that column, is calling the internet-speed hook, which is set up like this

$.fn.dataTableExt.oSort['internet-speed-pre'] = function(a){
a = a.toLowerCase();

    var factor = 1;
    if(a.indexOf('gbit') >= 0)
        factor = 1000;
    else if(a.indexOf('kbit') >= 0)
        factor = 1/1000;

    if(a.indexOf("/") >= 0){
        a = a.split("/");
        a = a[0];
    }

    a = (a==="-") ? 0 : a.replace('.', '').replace(',', '.').replace( /[^\d\-\.]/g, "" );

    a = parseFloat(a);

    if(isNaN(a))
        a = 0;

    a *= factor;

    return a;
}
$.fn.dataTableExt.oSort['internet-speed-asc'] = sort_asc;
$.fn.dataTableExt.oSort['internet-speed-desc'] = sort_desc;

How can I make it sort the same way, when its secondary?

Answers

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    It looks like it is already numeric sorting on the download column. Is that not working for you?

    Allan

  • spicywebspicyweb Posts: 3Questions: 1Answers: 0

    No. I thought it would work too, because the column has that sorting function "connected" to it :)

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    Could you describe what you would expect the sorted data to look like when you click on the first column (I assume that is where the issue is visible?). As I say, it looks like it is sorting correctly for me at the moment.

    Allan

  • spicywebspicyweb Posts: 3Questions: 1Answers: 0

    Of course :)

    If you click the UDBYDER column, then the DOWNLOAD column should sort, numeric.

    If you scroll down to view the Telia rows, then you can see, that the DOWNLOAD speed, is sorted wrong. 10 mbit comes before 2 mbit, even though it's faster.

    Does it make sense?

This discussion has been closed.