-
7 Mar 2012 4:08 PM #1
extjs 4 - treepanel - showing action column icon when mousing over a row
extjs 4 - treepanel - showing action column icon when mousing over a row
Hello,
Having an action column is a convenient way to work with a particular row in a treepanel. However, I find that it's excessive to have the same icon always displayed for every single row in the treepanel. It'd be much more elegant to display the action icon for the given row only when mousing over that row.
I have tried a few things but haven't been able to piece everything together...
Here is how I am listening for mouse over events:
Code:{ xtype: 'treepanel', ... { xtype:'actioncolumn', items: [{ icon: 'myicon.png', handler: function(grid, rowIndex, colIndex) { // do something when icon is clicked }, } listeners: { itemmouseenter: function( view, record, item, rowIndex, e, eOpts ) { // show the icon - is this possible? }, itemmouseleave: function( view, record, item, rowIndex, e, eOpts ) { // hide the icon } }
Any suggestions as to how to show/hide the icon from within the itemmouseenter/itemmouseleave function? Any ideas are much appreciated.
Thank you.
-
8 Mar 2012 2:19 PM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,714
- Vote Rating
- 438
Since you have the item, get the Ext.Element of it and find the icon then show/hide.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
8 Mar 2012 3:44 PM #3
Thank you very much, mitchellsimoens. This is exactly what I needed. For the record, here is the final code that works:
As you can see, I ended up using the id of the "item" in constructing the select statement, along with the icon name:Code:{ xtype: 'treepanel', ... { xtype:'actioncolumn', items: [{ icon: 'myicon.png', handler: function(grid, rowIndex, colIndex) { // do something when icon is clicked }, } listeners: { itemmouseenter: function( view, record, item, rowIndex, e, eOpts ) { // show the icon var cmp = Ext.select('#' + Ext.get(item).id +' [src~="myicon.png"]'); cmp.removeCls('x-hide-display'); cmp.addCls('x-grid-center-icon'); }, itemmouseleave: function( view, record, item, rowIndex, e, eOpts ) { // hide the icon var cmp = Ext.select('#' + Ext.get(item).id +' [src~="myicon.png"]'); cmp.removeCls('x-grid-center-icon'); cmp.addCls('x-hide-display'); } }
Once the component was found, the rest was easy - adding/removing the css class to show/hide the icon.Code:Ext.select('#' + Ext.get(item).id +' [src~="myicon.png"]')
Thanks again!
-
16 Mar 2012 7:55 PM #4
add action column
add action column
Could you a bit more codes? I tried the same thing, but the icon did not show up. thanks.
-
17 Mar 2012 1:12 PM #5
Hi ju187,
I am guessing that you may need to tweak the getClass method to specifically add the "x-hide-display" class to the column. Thus, the icon would be there but not shown.
Thus, once the mouse pointer is over the row, the itemmouseenter is invoked, where the 'x-hide-display' is replaced with 'x-grid-center-icon'. Hope this helps!Code:{ xtype:'actioncolumn', items: [{ icon: 'myicon.png', scope: this, getClass: function(value,meta,record,rowIx,colIx, store) { return 'x-hide-display'; //Hide the action icon } }] ...
-
17 Mar 2012 3:25 PM #6
-
26 Jun 2012 6:10 AM #7
-
19 Dec 2012 7:36 PM #8
Highlightitem
Highlightitem
Here's a slightly better (or just different?) version that uses the highlightitem event. This version has some advantages:
- Does not rely on component ids
- Works with both mouse and keyboard input
- Works for a list of actions (just an implementation detail really)
Code:listeners: { highlightitem: function(view, node, eOpts) { var rowEl = Ext.get(node); if (Ext.isEmpty(rowEl)) return; var actions = rowEl.query('[class~="x-action-col-icon"]'); if (Ext.isEmpty(actions)) return; for (var i = 0, len = actions.length; i < len; i++) { var el = Ext.get(actions[i]); if (!Ext.isEmpty(el) && el.hasCls('x-hide-display')) el.removeCls('x-hide-display'); } }, unhighlightitem: function(view, node, eOpts) { var rowEl = Ext.get(node); if (Ext.isEmpty(rowEl)) return; var actions = rowEl.query('[class~="x-action-col-icon"]'); if (Ext.isEmpty(actions)) return; for (var i = 0, len = actions.length; i < len; i++) { var el = Ext.get(actions[i]); if (!Ext.isEmpty(el) && !el.hasCls('x-hide-display')) el.addCls('x-hide-display'); } }


Reply With Quote