Get the currentRow when clicking a button in a table


I want to send the month of this row to an API endpoint.

If you Click on the cell then it runs a script.

  • First issue is that I sometimes have the feeling I have to click twice on that button. One time to select the table/row and second time to Click Cell.

Then I run this script:

//grab the month from this row:
const month = currentRow._id.month; 

//grab the year from the yearPicker. 
const year = yearPicker.selectedItem;

//put it together in the right formatting for the API endpoint. 
const formattedMonth = `${year}-${month.toString().padStart(2, '0')}`;
selected_month.setValue(formattedMonth);

//trigger the endpoint
await downloadCosts.trigger();

The first time this works (after clicking twice sometimes). The problem is that if I click two months quickly after each other, it sometimes still has the previous month in mind and sends that to the endpoint.

How can I fix this and make it reliable, so that you always get the data from that specific month back that you clicked. Should be pretty easy or?

Thanks so much for every help. :pray:

Hello @Tom_Suter

I think the "quick" fix and most direct answer to your question is to add a value to the debounce timer on your Run Script event. This should be at the bottom of the Click cell event handler edit menu.

Another thing you could consider is to use yourTableName.selectedRow instead of currentRow in your script. I just tested a button column and was able to get the selected row data without needing a new click. This may preclude the need for the debounce but if your users are fast clickers then a 500ms debounce is still unlikely to be a burden.

1 Like