Sort table using certain order

Sort table using certain order

islamelshobokshyislamelshobokshy Posts: 99Questions: 20Answers: 1
edited July 2018 in Free community support

I've got these values :

AH 18, AH 17, AH 16, AH 15, PE 18, PE 17, PE 16, PE 15... etc 

I want to be able to sort them, by clicking on the appropriate button, to this order :

AH 18, PE 18, AH 17, PE 17, AH 16, PE 16, AH 15, PE 15

How can I achieve that? I know how to manipulate order using this, this works as it orders them using numbers by removing the space and everything before, but by doing that I get PE 18, AH 18, PE 17, AH 17 ... etc and not the right order I want it to be.

columnDefs.push({"type": "num-fmt", "targets": i});
columnDefs.push({
    "targets": i, 
    "render": function ( data, type, row, meta ) {
            return type === 'sort' ?
        data.replace(/.*\s/g,'') : data;
    }
});

Help ? :smile:

Replies

  • kthorngrenkthorngren Posts: 21,301Questions: 26Answers: 4,946

    Sounds like you want to order by number first then the letters. I would first try swapping the order within the sort type, something like this:

    18AH, 17AH, 16AH, 15AH, 18PE, 17PE...

    Kevin

  • islamelshobokshyislamelshobokshy Posts: 99Questions: 20Answers: 1

    Gold, thanks @kthorngren !

This discussion has been closed.