chriscrossweb
chriscrossweb

Reputation: 348

Query for child component with a specific xtype

Is there a method to query for a child component of xtype 'yourxtype' ? For example you have a panel, and inside this panel is a custom xtype located on a toolbar.

The findParentByType works great for looking up, but there is not method like findChildByType. And the down method works only on elements. The Ext.ComponentQuery is a singleton, but not for xtypes? Is there another way to query from a component down?

Upvotes: 3

Views: 21407

Answers (4)

Nayas Subramanian
Nayas Subramanian

Reputation: 2379

This worked for me

This returns an array of instances with the mention xtype.

Ext.ComponentQuery.query('fieldxtype')

This returns only single instance i.e if we have 5 instances of the xtype.it will return only first instance of the xtype

formpanel.down('fieldxtype')

if you want get an component by name you can use

 var componentArray = Ext.ComponentQuery.query('[name=checkboxName]');

 var componentObj = Ext.ComponentQuery.query('[name=checkboxName]')[0];

Upvotes: 4

dbrin
dbrin

Reputation: 15673

You can simply query using Ext.ComponentQuery.query('myXtype') this will return an array of all instances of your type.

Upvotes: 1

Robert Watkins
Robert Watkins

Reputation: 2206

yourCt.down will find the first instance of a container with the specified type, in the component's children and descendants.

yourCt.child will do the same, but restrict to the direct children of the container.

yourCt.query will find all of the matching components underneath the container, as an array.

yourCt.up will find the first parent of the container that matches.

Oh, and Ext.ComponentQuery.query can take an optional object that is used as the start point for the query.

These are all based off (and clearly documented in) Ext.ComponentQuery

Upvotes: 11

rixo
rixo

Reputation: 25001

There is also a down method for component queries, but it is only available for containers. And component queries looks in xtypes for identifiers with no prefix (eg. "#", ".", etc.), it has no importance if the xtype is defined by Ext or your self. So jut do:

var child = yourCt.down('yourxtype');

Upvotes: 4

Related Questions