I have a table to be sorted. It has currently 3 columns:
currencyTd | accountNoTd | checkboxTd
I would like to sort it firstly by currency, then by checkbox (the checked ones to top) and lastly by account number. However, one modification is also needed - when initial loaded, the rows with a certain currency ("PLN") should be shown at the top of the table. Afterwards all remaining rows should be sorted as normally.
I use list.js to sort the rows. I have written the following sort function:
const options = {
valueNames: ['currencyTd', 'accountNoTd', 'checkboxTd']
};
const accountsList = new List('accountsList', options);
accountsList.sort('currencyTd', {
order: 'asc',
sortFunction: function (a, b) {
if ((a.currencyTd === 'PLN') != (b.currencyTd === 'PLN')) {
return a.currencyTd === 'PLN' ? 1 : -1;
}
return a.currencyTd > b.currencyTd ? 1 :
a.currencyTd < b.currencyTd ? -1 : 0;
}
});
But it's not working the way I expected. What may I do wrong?
EDIT: I forgot to add - the current function I write at this point (as in the code above) is supposed to sort it right just by the currency column. Whe I achieve it I want to add sorting by the other columns.