different iDataSort for sorting ascending and descending

different iDataSort for sorting ascending and descending

omeromer Posts: 5Questions: 0Answers: 0
edited November 2011 in DataTables 1.8
Is there any way to specity two iDataSort, for ascending and descending (on the same column, ofcourse)?

Replies

  • omeromer Posts: 5Questions: 0Answers: 0
    You know, kind of like:
    [code]
    "aoColumnDefs": [
    { "iDataSort": 1 asc, "aTargets": [ 0 ] } ,
    { "iDataSort": 2 desc, "aTargets": [ 0 ] }
    ]
    [/code]
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Currently no - there are however two options:

    1. Detach the sorting listener DataTables puts on the header element and then attach your own which will call fnSort with the sorting information you require.

    2. Define a sorting plug-in with a different 'asc' from 'desc' algorithm.

    I've not seen this done before I must admit, so its not something I've tried to do in DataTables, but the above methods (possibly with a bit more work?) should make it possible.

    Allan
  • omeromer Posts: 5Questions: 0Answers: 0
    Ah, thanks allan.

    It would be nice if I can implement point 2, but I think I'll end up with the same problem? i.e., I have access to the values of one column, and not the other?

    so if I have: { "iDataSort": 1 , "aTargets": [ 0 ] }
    [code]
    jQuery.fn.dataTableExt.oSort['pc-asc'] = function(a,b) {
    /*this is fine as I want to sort on column 1 for asc*/
    return ((x < y) ? -1 : ((x > y) ? 1 : 0));
    };

    jQuery.fn.dataTableExt.oSort['pc-desc'] = function(a,b) {
    /* I don't have access to column 2, so how do I sort using column 2 (for desc)*/
    return ((x < y) ? 1 : ((x > y) ? -1 : 0));
    };
    [/code]
This discussion has been closed.