I have a multi-select table.
I have a button for each row. When the button is clicked, I want to run a query for that specific row.
Most of the documentation seems to assume that table.selectedRow will give me the row for which the button is clicked. However, with a multi-select table this doesn't seem to be the case.
Is there another way I can get data in a query for the specific row on which the button is clicked?
Hi @phil_ds, welcome to the community!
Quick question: What's the need for the multi-select rows enabled in this instance?
The above question is relevant because your
table.selectedRow will be in a form of
Array<Object> instead of just
Object. If you disable the multi-select feature, it will work well as the documentation said.
If you need to have the multi-select rows enabled, then you have to write a JS query for the button to work as you intended.
My setup is I want to run an action simultaneously on multiple rows in the table, for the purpose of sending an email about the selected items.
At the same time, I have buttons in each row of the table. When the button is clicked, I want to run a query for that specific row.
Normally, it seems to identify which row the button is clicked for the recommendation is to use table.selectedRow. However as I mentioned above, I may have multiple rows already selected.
Hope that explains my use case a bit more.
I do not see any capability to handle @jocen's scenario. I tried testing something using the index of each selected row but that doesn't work when multiple rows are selected.
@jocen - you may have to think of a different approach for what you are trying to accomplish. This is of course only based on my knowledge - perhaps someone else may know more or may know of a solution - best of luck.
Yeah, agreed on you with that @ScottR, I actually have not test a JS query on that. @phil_ds you might want to separate those two scenarios into two tables; one for selecting the ones you want to email, another for the button functionality.
Even when you have multi select enabled for table components, they will still pass
i to the scope of any query that a button row triggers. Using that you can index into the table data to check values for that clicked row.
Oh that's great to know. Are there any other things that are passed to the scope, maybe the table it got triggered from? (Kind of like DOM events?)
You might want to try the
triggeredById variable, these docs are a great place to find a bunch of tricks with running queries!
Thanks! That works.
Is there a way to dynamically access an element by Id?
i have a multi select form and would like to insert the selected values in different rows in a database, how any suggestions on how to approach this ?
DB STRUCTURE ?
FORM to insert into postcategory
Not sure if this is the best way but the way I see it, you would be doing a JS Query to run through the list and then insert them individually to the database.
- Create individual query for inserting data on each table
- Create JS query on scripting through the data in the multiselect form
- Use promises to not overlap the data you pushed to the db
Yes, it's great, thank you for sharing
i as @lauren.gus proposed, and I have an index of row in that table where the button was clicked, BUT the table which I'm using has enabled sorting on the columns and in
Table. displayedData data are in the original form, so this index doesn't work well.
Do you know how I can take the correct row even if someone on the UI clicked sort on some of the columns?
i is a passed index in a really displayed table when it is triggered by clicking the action button in the table, even if rows are manipulated(sorted etc).
It looks like
i is an index in original table data when it is triggered by clicking on the custom cell as a button.
Thanks for sharing how you resolved this issue