Question to CheckBoxGroup mapping, default some on and other off

I'm using the CheckBoxGroup to allow users to select columns in table to show.

I have MySQL query to populate my table.

  1. How can I use mapped to extract the column headings name only as labels from my query or do i need to create a separate SQL?

  2. Is it possible to have some of them ticked off and some not as default?

Or maybe create a view selection that only has default view with selection stored and the check box group used this?
image

In the future maybe I want the user to be able to save his selection as a view. but for now I'm using free trial of retool for testing out reTool.

Hello!

For #1:
{{ Object.keys(formatDataAsObject(yourQuery.data)) }}

For #2: I'm not quite sure about defaults, but you could have a settings table for these options to call upon per user.

1 Like

Follow up to this, it does look like you can have Options selected via a script action or event handler that controls the component:

image

The base could just be a variable that is set to your default array of options and then is updated when a user is in the app. In the future, the values can be pulled directly from User Attributes in Retool to store user-specific defaults.

Where shall i add this
My SQL query name is "Get_tasklist" so i asume that the script will be like this:
{{ Object.keys(formatDataAsObject(Get_tasklist.data)) }}

It would be the data source for your Checkbox Group:

image

Hi @pyrrho
I needed to use .dataArray in my code. This list up all the fields.
I see that the some of the headings starts with "fld"

I have renamed the label in the table without fld. Do you know how of a script that i can add to the checkbox group Label that will remove fld where this is present?

-Thore

In the mapped options for Label you can use something like:

{{ item.startsWith('fld') ? item.slice(3) : item }}

Thank you @pyrrho for the help with this.

1 Like