Unanswered: Adding event handler for dynamically added button
I have added a button to a grid column using following link:
While I am able to add the button, I want to show a image to the button based on certain condition. Where should I write code to handle this condition. Basically I first want to check the condition and then using iconCls config I want to set the image.
I have a store which have number between 1 to 50. When user clicks on a button, I open a window and in a grid, I show button (one button for each number in each row). The button have a image which show add symbol stating the item is not been added. Now user can click on any button and as soon as he clicks the button, I should change the button image to minus and should add the record to SelectedStore.
Now the next time the image is loaded, I should search in SelectedStore and if that item is already been added, the image should show minus symbol.
I want to understand where can I write this logic of checking for values in another store and then applying the image.
Thanks in advance.
You may find it easier to use this UX:
The article you referenced fails to mention the potential for memory leaks. Unless you destroy those button components yourself they will leak. The UX above handles that automatically.
The title of this thread is about event handlers, yet your question seems to be about icons. It's a little unclear what you're trying to do. If you just want to set the icon based on some criteria, isn't that just the same as setting the text?
I have updated the problem statement. Thank you.
If clicking the button causes the data to change in the record that is used to render that grid row then it will cause it to re-render. This makes it pretty straightforward to switch the icon.
If clicking the button updates data in a different store then the grid won't re-render. In that case you've got two options. Either force it to re-render manually, or call setIconCls on the button.