Issue
As a developer, I need to be able to assign event callbacks to dynamically created buttons in code, so that I can make my tables editable and have corresponding callbacks. How can this be achieved programmatically?
Resolution
Create a JS Object named MyJsObject with the following code snippet:
export default {
  myFunc1: () => { 
    showAlert('Ran myFunc1')
    return true
  }
}Elsewhere in your JS, you can use the following line to store the function to the Appsmith Store: await storeValue('myWellNamedCallback', MyJsObject['myFunc1'])
In your button's onClick Event, you can use {{ appsmith.store.myWellNamedCallback?.() || myFallbackFunc() }}
You want any callback you define in your object to return true, so that we can use the OR operator (||) to define a fallback in case we haven’t stored a function yet.