-
5 Oct 2012 10:32 AM #1
Unanswered: How can I tell if a grid has plugins?
Unanswered: How can I tell if a grid has plugins?
I have button that serves two grids. In the handler, it has this:
One grid has plugins, and it works fine. The other throws "plugins is undefined". I could useCode:if(button.up('grid').getPlugin('roweditor').editing) { ...
but that depends on the plugins attribute. Can anyone think of a better way?Code:var grid = button.up('grid'); if(grid.plugins && grid.getPlugin('roweditor').editing) { ...word
-
5 Oct 2012 11:42 AM #2
If calling getPlugin causes an error to be thrown I'd say it's a bug. Your workaround looks sensible but it'd probably be worth filing it in the bugs forum to get it fixed properly.
-
5 Oct 2012 2:57 PM #3Sencha - Support Team
- Join Date
- Jul 2010
- Location
- Houston, Tx
- Posts
- 7,185
- Vote Rating
- 194
- Answers
- 433
You should be able to call without error. Is this present in a older/newer release?
Scott.Code:pluginId: 'myPluginId', grid.getPlugin('myPluginId');
-
5 Oct 2012 3:18 PM #4
@scottmartin. I believe the problem being observed is that an error is thrown if the component doesn't have any plugins. For consistency (and common sense) it should just return undefined if the plugin id isn't found.
-
5 Oct 2012 3:41 PM #5Sencha - Support Team
- Join Date
- Jul 2010
- Location
- Houston, Tx
- Posts
- 7,185
- Vote Rating
- 194
- Answers
- 433
Understood... this seems to work:
Scott.Code:var myPlugin = grid.getPlugin('IdoNoExist'); if (myPlugin === undefined) { console.log('undefined'); }
-
6 Feb 2013 8:15 PM #6
A developer on my team thinks this is a bug and I agree with him. I'll make his case below: I just created this JSFiddle http://jsfiddle.net/LMaaM/.
This is based on 4.1.1 (not 4.1.3) which is latest. The test is obviously pretty contrived. However, I think it still illustrates the bug since in one case it works fine and in the other case it fails. This has to do with the fact that the code for the getPlugins code in Ext.AbstractComponent is:
My developer's thought is that the plugins.length check fails since plugins doesn't exist. Plugins isn't obligated to be defined.Code:/** * Retrieves a plugin by its `pluginId` which has been bound to this component. * @param {String} pluginId * @return {Ext.AbstractPlugin} plugin instance. */ getPlugin: function(pluginId) { var i = 0, plugins = this.plugins, ln = plugins.length; //problematic for (; i < ln; i++) { if (plugins[i].pluginId === pluginId) { return plugins[i]; } } },
The AbstractComponent.constructPlugins method isn't obligated to assign an array to plugins or return an array that would be assign to plugins from any calls while initializing the component. The configuration option isn't defined as an array by default (wisely) either.
I'd say there's two options to repair:
- getPlugins (and any other methods utilizing the plugins member variable) could guard against the case that the plugins array is undefined.
- plugins could be initialized as an empty array by default, reducing the need to check
I'd guess the latter would be the better choice from a future proofing standpoint.
-
11 Feb 2013 10:59 AM #7
Bug was eventually recognized as EXTJSIV-8568: http://www.sencha.com/forum/showthre...ed-as-an-array


Reply With Quote