You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am sorting a column in a table. Column has some blank values. My aim is to sort ONLY non-blank values, and the blank values must always come AFTER non-blank values.
Here's the Custom Sort JavaScript function:
function customSort(a, b, options) {
let valA = a.values()[options.valueName];
let valB = b.values()[options.valueName];
let isBlankA = (valA === '');
let isBlankB = (valB === '');
if (isBlankA && isBlankB) {
return 0;
} else if (isBlankA) {
return 1;
} else if (isBlankB) {
return -1;
} else {
if (valA === valB) {
return 0;
}
if (options.order === 'asc') {
return valA < valB ? -1 : 1;
}
else {
return valA < valB ? 1 : -1;
}
return 0;
}
}
And here's how I am calling it: sortMapList.sort(colName, { order: sortDir, sortFunction: customSort });
When I send sortDir = 'asc' the column gets sorted in 'desc' order! and vice-versa