PDA

View Full Version : Adding event handler for dynamically added button



webfriend13
5 Mar 2012, 11:29 PM
Hi All,

I have added a button to a grid column using following link:
http://techmix.net/blog/2010/11/25/add-button-to-extjs-gridpanel-cell-using-renderer/

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.

skirtle
6 Mar 2012, 12:19 AM
You may find it easier to use this UX:

http://www.sencha.com/forum/showthread.php?148064

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?

webfriend13
6 Mar 2012, 1:01 AM
Hi Skirtlte,

I have updated the problem statement. Thank you.

skirtle
6 Mar 2012, 1:28 AM
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.