Custom Default Ordering by classname -> defaultSortASC & defaultSortDESC

Custom Default Ordering by classname -> defaultSortASC & defaultSortDESC

SvenoSveno Posts: 8Questions: 2Answers: 0

hey ho,
i'm a german guy and sorry for my bad english :)

i have one question, in my project, i use a class to set the default-ordering

myclass -> defaultSort

$('#datatables').DataTable( {
    "order": [[$('th.defaultSort').index(),'desc'] ]
});

now i want to set the ordering-direction with class names
new classes: defaultSortASC & defaultSortDESC

i tried to figure out with jquery:

var order = [[$('th.defaultSort').index(),'desc'] ]
if ($(".defaultSortASC ").length ) {
    order = [[$('th.defaultSortASC ').index(),'asc'] ]
}
else if ($(".defaultSortASC ").length ) {
    order = [[$('th.defaultSortDESC').index(),'desc'] ]
}
$('#datatables').DataTable( {
    "order": order 
});

but it dont work and i think it depends on the .index()

can someone help me to solve the problem :)

greetings from Hamburg

Answers

  • SvenoSveno Posts: 8Questions: 2Answers: 0

    3 Minutes after post my problem, i solved it.

    i used 2 classes to handle it.
    one for default order -> "defaultSort" and one for the direction -> "ASC" or "DESC"

        var direction = 'asc';
        if($(".DESC").length ) {
          direction = 'desc';
        }
        if($(".ASC").length ) {
          direction = 'asc';
        }
        $('#datatables').DataTable( {
             "order": [[$('th.defaultSort').index(), direction] ]
        });
    
This discussion has been closed.