Select/unselect all in one go in dropdown input

  1. My goal: i need a select all button in dropdown to select and unselect all options from dropdown. is there a way to do that as i dont see a option in retool?

Hi @Sudeep, that is not currently an option for the multiselect component, but there is an existing feature request out for it, and I have a javascript workaround if you're interested.

if (multiselect1.data.length === multiselect1.selectedIndexes.length) {
  // first we clear if all options are selected
  await multiselect1.clearValue();
} else if (multiselect1.selectedIndexes.includes(0)) {
  // otherwise we just check to see if the "select all" is chosen
  const valuesArray = []; 

  for (const item of multiselect1.data.slice(1)) { 
      valuesArray.push(item.value);
  }
  await multiselect1.setValue(valuesArray);
}

return multiselect1.value;

You then just have the first option be a "Select/Deselect All" option, and have the multiselect call this on a "change" event. The way I have the function set up, it will not include the "select all" as an option.

Hey @Mike_M Thank you so much for the reply
it works fine when working with form, i need similar functionality in the table where in i have column and each row has a select option when clicked on select option you see bunch of options. is there a way to select or deselect all ?
i tried here but i wasn’t able to achieve the same here

Making this work for the table is a bit different, since we can't programmatically modify the changesetArray or changesetObject of the table, so I have an alternate workaround/solution for this.

My advice would be to create an additional column, that is type "Button", which calls a query that updates the database with all of the options selected. On a successful save, the table should refetch all the data. You can use similar logic for a Deselect button, or have one button do both, with some conditional logic which checks if the length of the array for that column is equal to the list of options.

Let me know if this helps!

1 Like