Disable event handler for programmatic triggers?

Hi!

Is there a way to distinguish between user-triggered and programmatically triggered events?

For example, I have a scenario where I programmatically select rows in a table, and another where the user manually selects a row. There is an event handler set up on the “select row” event, but I only want it to run for manual row selections.

Thanks!

@axel.trolle - Hey again :waving_hand:

I bit difficult to know the best solution without being in the environment but a quick solution would be to add a variable thats called MANUAL_TRIGGER that defaults to be true. then on the selectRow event handler, add to the “only run when” section when MANUAL_TRIGGER == true

Now, when you call the query that will programatically select rows have a JS query thats

await MANUAL_TRIGGER.setValue(false)
await queryToTrigger.trigger()
await MANUAL_TRIGGER.setValue(true)

hope that helps!

1 Like

Solution 1: Use a Button for Manual Action

  1. Remove the automatic handler. Do not connect your event handler directly to the table’s "select row" event.

  2. Add a Button next to your table, called "Do Action" or similar.

  3. On the Button’s click event, put your custom logic or query.

    • This way, only real user clicks on the button will trigger your action, not programmatic row selections.

Solution 2: Track Previous Selected Row

  1. Create a temporary state variable (call it PREV_ROW_INDEX).

  2. On the table’s select row event, compare the newly selected row index with PREV_ROW_INDEX.

  3. Only run your action if the index is different and user-initiated:

    • Example JavaScript condition:

      js
      

      if(table1.selectedRow.index !== PREV_ROW_INDEX.value) { // run your logic here PREV_ROW_INDEX.setValue(table1.selectedRow.index) }

    • This checks if user really selected a new row before running your code.

1 Like

Thanks for reaching out, @axel.trolle! I don't think there's a natively supported solution to this particular problem, but you can certainly wire up any number of functional solutions.

@DavidD outlined one such solution above - essentially, define a globally scoped variable that can be toggled on and off and then referenced in order to determine whether or not the handler should trigger. Let us know if you have any questions about implementing something like this. :+1: