I'm following this link Selecting Multiple Values from a Dropdown List in Google Spreadsheet, it works very well. For Example if i have dropdown with three values like "Red, Black, Green" , and i select "Red & Black" it prints Red & Black perfectly fine, now if i select "Black & Red" it prints respectively. The problem now is if i filter this column in spreadsheet these "Red & Black", "Black & Red" are taken as seperate values which does not make sense because both are same. How can it be done where if i select in any manner it should print alphabattically? any leads? thanks.
Asked
Active
Viewed 186 times
2
-
Do you have so many that you cannot add combinations of them on to the list. For example how about a list like this `["1","2","3","1&2","1&3","2&3","1&2&3"]`. If the number of selections is x the the number of combinations with be (2 to x power) -1 since not making a selection is also one of the options. So with four there will be 15 and 5 will be 31 so after a while it gets unwieldy. But you can always figure them out with a truth table or write a function to do it for you. Of course the column width starts to become an issue as well but I suppose you can leave a space so that will wrap – Cooper Nov 15 '21 at 20:59
-
I would consider using x columns. – Cooper Nov 15 '21 at 21:02
1 Answers
3
Here is the possible solution.
You can add this function a the end of multi-select.gs
file:
function sort_contents() {
var range = SpreadsheetApp.getActiveRange();
var values = range.getValues();
var sorted_values = values.map(row => [row[0].split(',').sort().join(',')]);
range.setValues(sorted_values);
}
Add this function into the dialog.html
file, after the function function reset() {...}
:
function sort_contents() {
google.script.run.withSuccessHandler(x=>{}).sort_contents()
}
And add one more button in the dialog.html
:
<input type="button" value="Sort" onclick="sort_contents()" />
After that you will have the button 'Sort' that will sort the contents of selected cell (and cells, you can select several cells) alphabetically. So you will able to sort 'Red, Black' into 'Black, Red' anytime.

Yuri Khristich
- 13,448
- 2
- 8
- 23