Currently I sort my sheet via this function
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName(a);
var dataRange = sheet.getDataRange();
dataRange.sort([
{column: role, ascending: true},
{column: cases, ascending: false}
]);
This sorts the by role first in alphabetical order. Is it possible to customise this sort ?
For example, ideally the sort is by role level and not aplhabetical
Eg. if the roles are [intern, junior, senior, lead, manager] can the sheet be sorted in that order ?
2
Answers
You can use a
Map
object to assign a numerical value to each role and sort based on those values. Hopefully this works as intended.Sorts the role level using ForEach
By sorting the level from intern to manager, all of the data from your dataRange will be retrieved, and the setValues will be returned to the designated range.
Sample Table:
Output Table:
Script:
Reference:
forEach
Ternary