Ext.data.JsonP.Ext_ComponentQuery({"alternateClassNames":[],"aliases":{},"enum":null,"parentMixins":[],"tagname":"class","subclasses":[],"extends":"Ext.Base","uses":[],"html":"
Hierarchy
Ext.BaseExt.ComponentQueryRequires
Files
Provides searching of Components within Ext.ComponentManager (globally) or a specific\nExt.container.Container on the document with a similar syntax to a CSS selector.\nReturns Array of matching Components, or empty Array.
\n\nComponents can be retrieved by using their xtype:
\n\ncomponent
gridpanel
Matching by xtype
matches inherited types, so in the following code, the previous field\nof any type which inherits from TextField
will be found:
prevField = myField.previousNode('textfield');\n
\n\nTo match only the exact type, pass the \"shallow\" flag by adding (true)
to xtype\n(See AbstractComponent's isXType method):
prevTextField = myField.previousNode('textfield(true)');\n
\n\nYou can search Components by their id
or itemId
property, prefixed with a #:
#myContainer\n
\n\nComponent xtype
and id
or itemId
can be used together to avoid possible\nid collisions between Components of different types:
panel#myPanel\n
\n\nComponents can be found by their relation to other Components. There are several\nrelationship operators, mostly taken from CSS selectors:
\n\nE F
All descendant Components of E that match FE > F
All direct children Components of E that match FE ^ F
All parent Components of E that match FExpressions between relationship operators are matched left to right, i.e. leftmost\nselector is applied first, then if one or more matches are found, relationship operator\nitself is applied, then next selector expression, etc. It is possible to combine\nrelationship operators in complex selectors:
\n\nwindow[title=\"Input form\"] textfield[name=login] ^ form > button[action=submit]\n
\n\nThat selector can be read this way: Find a window with title \"Input form\", in that\nwindow find a TextField with name \"login\" at any depth (including subpanels and/or\nFieldSets), then find an Ext.form.Panel
that is a parent of the TextField, and in\nthat form find a direct child that is a button with custom property action
set to\nvalue \"submit\".
Whitespace on both sides of ^
and >
operators is non-significant, i.e. can be\nomitted, but usually is used for clarity.
Components can be searched by their object property values (attributes). To do that,\nuse attribute matching expression in square brackets:
\n\ncomponent[autoScroll]
- matches any Component that has autoScroll
property with\nany truthy (non-empty, not false
) value.panel[title=\"Test\"]
- matches any Component that has title
property set to\n\"Test\". Note that if the value does not contain spaces, the quotes are optional.Attributes can use any of the operators in DomQuery's\noperators to compare values.
\n\nPrefixing the attribute name with an at sign @
means that the property must be\nthe object's ownProperty
, not a property from the prototype chain.
Specifications like [propName]
check that the property is a truthy value. To check\nthat the object has an ownProperty
of a certain name, regardless of the value use\nthe form [?propName]
.
The specified value is coerced to match the type of the property found in the\ncandidate Component using Ext.coerce.
\n\nIf you need to find Components by their itemId
property, use #id
form; it will\ndo the same but is easier to read.
The '=' operator will return the results that exactly match the\nspecified object property (attribute):
\n\nExt.ComponentQuery.query('panel[cls=my-cls]');\n
\n\nWill match the following Component:
\n\nExt.create('Ext.window.Window', {\n cls: 'my-cls'\n});\n
\n\nBut will not match the following Component, because 'my-cls' is one value\namong others:
\n\n Ext.create('Ext.panel.Panel', {\n cls: 'foo-cls my-cls bar-cls'\n });\n
\n\nYou can use the '~=' operator instead, it will return Components with\nthe property that exactly matches one of the whitespace-separated\nvalues. This is also true for properties that only have one value:
\n\nExt.ComponentQuery.query('panel[cls~=my-cls]');\n
\n\nWill match both Components:
\n\nExt.create('Ext.panel.Panel', {\n cls: 'foo-cls my-cls bar-cls'\n});\n\nExt.create('Ext.window.Window', {\n cls: 'my-cls'\n});\n
\n\nGenerally, '=' operator is more suited for object properties other than\nCSS classes, while '~=' operator will work best with properties that\nhold lists of whitespace-separated CSS classes.
\n\nThe '=' operator will return Components with specified attribute that\nstart with the passed value:
\n\nExt.ComponentQuery.query('panel[title^=Sales]');\n
\n\nWill match the following Component:
\n\nExt.create('Ext.panel.Panel', {\n title: 'Sales estimate for Q4'\n});\n
\n\nThe '$=' operator will return Components with specified properties that\nend with the passed value:
\n\nExt.ComponentQuery.query('field[fieldLabel$=name]');\n
\n\nWill match the following Component:
\n\nExt.create('Ext.form.field.Text', {\n fieldLabel: 'Enter your name'\n});\n
\n\nThe following test will find panels with their ownProperty
collapsed being equal to\nfalse
. It will not match a collapsed property from the prototype chain.
Ext.ComponentQuery.query('panel[@collapsed=false]');\n
\n\nMember expressions from candidate Components may be tested. If the expression returns\na truthy value, the candidate Component will be included in the query:
\n\nvar disabledFields = myFormPanel.query(\"{isDisabled()}\");\n
\n\nSuch expressions are executed in Component's context, and the above expression is\nsimilar to running this snippet for every Component in your application:
\n\n if (component.isDisabled()) {\n matches.push(component);\n }\n
\n\nIt is important to use only methods that are available in every Component instance\nto avoid run time exceptions. If you need to match your Components with a custom\ncondition formula, you can augment Ext.Component
to provide custom matcher that\nwill return false
by default, and override it in your custom classes:
Ext.define('My.Component', {\n override: 'Ext.Component',\n myMatcher: function() { return false; }\n });\n\n Ext.define('My.Panel', {\n extend: 'Ext.panel.Panel',\n requires: ['My.Component'], // Ensure that Component override is applied\n myMatcher: function(selector) {\n return selector === 'myPanel';\n }\n });\n
\n\nAfter that you can use a selector with your custom matcher to find all instances\nof My.Panel
:
Ext.ComponentQuery.query(\"{myMatcher('myPanel')}\");\n
\n\nHowever if you really need to use a custom matcher, you may find it easier to implement\na custom Pseudo class instead (see below).
\n\nAttribute matchers can be combined to select only Components that match all\nconditions (logical AND operator):
\n\nExt.ComponentQuery.query('panel[cls~=my-cls][floating=true][title$=\"sales data\"]');\n
\n\nE.g., the query above will match only a Panel-descended Component that has 'my-cls'\nCSS class and is floating and with a title that ends with \"sales data\".
\n\nExpressions separated with commas will match any Component that satisfies\neither expression (logical OR operator):
\n\nExt.ComponentQuery.query('field[fieldLabel^=User], field[fieldLabel*=password]');\n
\n\nE.g., the query above will match any field with field label starting with \"User\",\nor any field that has \"password\" in its label.
\n\nPseudo classes may be used to filter results in the same way as in\nExt.dom.Query. There are five default pseudo classes:
\n\nnot
Negates a selector.first
Filters out all except the first matching item for a selector.last
Filters out all except the last matching item for a selector.focusable
Filters out all except Components which are currently able to recieve\nfocus.nth-child
Filters Components by ordinal position in the selection.These pseudo classes can be used with other matchers or without them:
\n\n // Select first direct child button in any panel\n Ext.ComponentQuery.query('panel > button:first');\n\n // Select last field in Profile form\n Ext.ComponentQuery.query('form[title=Profile] field:last');\n\n // Find first focusable Component in a panel and focus it\n panel.down(':focusable').focus();\n\n // Select any field that is not hidden in a form\n form.query('field:not(hiddenfield)');\n
\n\nPseudo class nth-child
can be used to find any child Component by its\nposition relative to its siblings. This class' handler takes one argument\nthat specifies the selection formula as Xn
or Xn+Y
:
// Find every odd field in a form\n form.query('field:nth-child(2n+1)'); // or use shortcut: :nth-child(odd)\n\n // Find every even field in a form\n form.query('field:nth-child(2n)'); // or use shortcut: :nth-child(even)\n\n // Find every 3rd field in a form\n form.query('field:nth-child(3n)');\n
\n\nPseudo classes can be combined to further filter the results, e.g., in the\nform example above we can modify the query to exclude hidden fields:
\n\n // Find every 3rd non-hidden field in a form\n form.query('field:not(hiddenfield):nth-child(3n)');\n
\n\nNote that when combining pseudo classes, whitespace is significant, i.e.\nthere should be no spaces between pseudo classes. This is a common mistake;\nif you accidentally type a space between field
and :not
, the query\nwill not return any result because it will mean \"find field's children\nComponents that are not hidden fields...\".
It is possible to define your own custom pseudo classes. In fact, a\npseudo class is just a property in Ext.ComponentQuery.pseudos
object\nthat defines pseudo class name (property name) and pseudo class handler\n(property value):
// Function receives array and returns a filtered array.\nExt.ComponentQuery.pseudos.invalid = function(items) {\n var i = 0, l = items.length, c, result = [];\n for (; i < l; i++) {\n if (!(c = items[i]).isValid()) {\n result.push(c);\n }\n }\n return result;\n};\n\nvar invalidFields = myFormPanel.query('field:invalid');\nif (invalidFields.length) {\n invalidFields[0].getEl().scrollIntoView(myFormPanel.body);\n for (var i = 0, l = invalidFields.length; i < l; i++) {\n invalidFields[i].getEl().frame(\"red\");\n }\n}\n
\n\nPseudo class handlers can be even more flexible, with a selector\nargument used to define the logic:
\n\n // Handler receives array of itmes and selector in parentheses\n Ext.ComponentQuery.pseudos.titleRegex = function(components, selector) {\n var i = 0, l = components.length, c, result = [], regex = new RegExp(selector);\n for (; i < l; i++) {\n c = components[i];\n if (c.title && regex.test(c.title)) {\n result.push(c);\n }\n }\n return result;\n }\n\n var salesTabs = tabPanel.query('panel:titleRegex(\"sales\\\\s+for\\\\s+201[123]\")');\n
\n\nBe careful when using custom pseudo classes with MVC Controllers: when\nyou use a pseudo class in Controller's control
or listen
component\nselectors, the pseudo class' handler function will be called very often\nand may slow down your application significantly. A good rule of thumb\nis to always specify Component xtype with the pseudo class so that the\nhandlers are only called on Components that you need, and try to make\nthe condition checks as cheap in terms of execution time as possible.\nNote how in the example above, handler function checks that Component\nhas a title first, before running regex test on it.
Queries return an array of Components. Here are some example queries:
\n\n// retrieve all Ext.Panels in the document by xtype\nvar panelsArray = Ext.ComponentQuery.query('panel');\n\n// retrieve all Ext.Panels within the container with an id myCt\nvar panelsWithinmyCt = Ext.ComponentQuery.query('#myCt panel');\n\n// retrieve all direct children which are Ext.Panels within myCt\nvar directChildPanel = Ext.ComponentQuery.query('#myCt > panel');\n\n// retrieve all grids or trees\nvar gridsAndTrees = Ext.ComponentQuery.query('gridpanel, treepanel');\n\n// Focus first Component\nmyFormPanel.child(':focusable').focus();\n\n// Retrieve every odd text field in a form\nmyFormPanel.query('textfield:nth-child(odd)');\n\n// Retrieve every even field in a form, excluding hidden fields\nmyFormPanel.query('field:not(hiddenfield):nth-child(even)');\n
\n\nFor easy access to queries based from a particular Container see the\nExt.container.Container.query, Ext.container.Container.down and\nExt.container.Container.child methods. Also see\nExt.Component.up.
\nGet the reference to the current class from which this object was instantiated. Unlike statics,\nthis.self
is scope-dependent and it's meant to be used for dynamic inheritance. See statics\nfor a detailed comparison
Ext.define('My.Cat', {\n statics: {\n speciesName: 'Cat' // My.Cat.speciesName = 'Cat'\n },\n\n constructor: function() {\n alert(this.self.speciesName); // dependent on 'this'\n },\n\n clone: function() {\n return new this.self();\n }\n});\n\n\nExt.define('My.SnowLeopard', {\n extend: 'My.Cat',\n statics: {\n speciesName: 'Snow Leopard' // My.SnowLeopard.speciesName = 'Snow Leopard'\n }\n});\n\nvar cat = new My.Cat(); // alerts 'Cat'\nvar snowLeopard = new My.SnowLeopard(); // alerts 'Snow Leopard'\n\nvar clone = snowLeopard.clone();\nalert(Ext.getClassName(clone)); // alerts 'My.SnowLeopard'\n
\nCall the original method that was previously overridden with override
\n\nExt.define('My.Cat', {\n constructor: function() {\n alert(\"I'm a cat!\");\n }\n});\n\nMy.Cat.override({\n constructor: function() {\n alert(\"I'm going to be a cat!\");\n\n this.callOverridden();\n\n alert(\"Meeeeoooowwww\");\n }\n});\n\nvar kitty = new My.Cat(); // alerts \"I'm going to be a cat!\"\n // alerts \"I'm a cat!\"\n // alerts \"Meeeeoooowwww\"\n
\n This method has been deprecated
\nas of 4.1. Use callParent instead.
\n\nThe arguments, either an array or the arguments
object\nfrom the current method, for example: this.callOverridden(arguments)
Returns the result of calling the overridden method
\nCall the \"parent\" method of the current method. That is the method previously\noverridden by derivation or by an override (see Ext.define).
\n\n Ext.define('My.Base', {\n constructor: function (x) {\n this.x = x;\n },\n\n statics: {\n method: function (x) {\n return x;\n }\n }\n });\n\n Ext.define('My.Derived', {\n extend: 'My.Base',\n\n constructor: function () {\n this.callParent([21]);\n }\n });\n\n var obj = new My.Derived();\n\n alert(obj.x); // alerts 21\n
\n\nThis can be used with an override as follows:
\n\n Ext.define('My.DerivedOverride', {\n override: 'My.Derived',\n\n constructor: function (x) {\n this.callParent([x*2]); // calls original My.Derived constructor\n }\n });\n\n var obj = new My.Derived();\n\n alert(obj.x); // now alerts 42\n
\n\nThis also works with static methods.
\n\n Ext.define('My.Derived2', {\n extend: 'My.Base',\n\n statics: {\n method: function (x) {\n return this.callParent([x*2]); // calls My.Base.method\n }\n }\n });\n\n alert(My.Base.method(10); // alerts 10\n alert(My.Derived2.method(10); // alerts 20\n
\n\nLastly, it also works with overridden static methods.
\n\n Ext.define('My.Derived2Override', {\n override: 'My.Derived2',\n\n statics: {\n method: function (x) {\n return this.callParent([x*2]); // calls My.Derived2.method\n }\n }\n });\n\n alert(My.Derived2.method(10); // now alerts 40\n
\n\nTo override a method and replace it and also call the superclass method, use\ncallSuper. This is often done to patch a method to fix a bug.
\nThe arguments, either an array or the arguments
object\nfrom the current method, for example: this.callParent(arguments)
Returns the result of calling the parent method
\nThis method is used by an override to call the superclass method but bypass any\noverridden method. This is often done to \"patch\" a method that contains a bug\nbut for whatever reason cannot be fixed directly.
\n\nConsider:
\n\n Ext.define('Ext.some.Class', {\n method: function () {\n console.log('Good');\n }\n });\n\n Ext.define('Ext.some.DerivedClass', {\n method: function () {\n console.log('Bad');\n\n // ... logic but with a bug ...\n\n this.callParent();\n }\n });\n
\n\nTo patch the bug in DerivedClass.method
, the typical solution is to create an\noverride:
Ext.define('App.paches.DerivedClass', {\n override: 'Ext.some.DerivedClass',\n\n method: function () {\n console.log('Fixed');\n\n // ... logic but with bug fixed ...\n\n this.callSuper();\n }\n });\n
\n\nThe patch method cannot use callParent
to call the superclass method
since\nthat would call the overridden method containing the bug. In other words, the\nabove patch would only produce \"Fixed\" then \"Good\" in the console log, whereas,\nusing callParent
would produce \"Fixed\" then \"Bad\" then \"Good\".
The arguments, either an array or the arguments
object\nfrom the current method, for example: this.callSuper(arguments)
Returns the result of calling the superclass method
\nInitialize configuration for this class. a typical example:
\n\nExt.define('My.awesome.Class', {\n // The default config\n config: {\n name: 'Awesome',\n isAwesome: true\n },\n\n constructor: function(config) {\n this.initConfig(config);\n }\n});\n\nvar awesome = new My.awesome.Class({\n name: 'Super Awesome'\n});\n\nalert(awesome.getName()); // 'Super Awesome'\n
\nthis
\nTests whether the passed Component matches the selector string.
\nThe Component to test
\nThe selector string to test against.
\nTrue if the Component matches the selector.
\nReturns an array of matched Components from within the passed root object.
\n\nThis method filters returned Components in a similar way to how CSS selector based DOM\nqueries work using a textual selector string.
\n\nSee class summary for details.
\nThe selector string to filter returned Components
\nThe Container within which to perform the query.\nIf omitted, all Components within the document are included in the search.
\n\nThis parameter may also be an array of Components to filter according to the selector.
\nThe matched Components.
\nGet the reference to the class from which this object was instantiated. Note that unlike self,\nthis.statics()
is scope-independent and it always returns the class from which it was called, regardless of what\nthis
points to during run-time
Ext.define('My.Cat', {\n statics: {\n totalCreated: 0,\n speciesName: 'Cat' // My.Cat.speciesName = 'Cat'\n },\n\n constructor: function() {\n var statics = this.statics();\n\n alert(statics.speciesName); // always equals to 'Cat' no matter what 'this' refers to\n // equivalent to: My.Cat.speciesName\n\n alert(this.self.speciesName); // dependent on 'this'\n\n statics.totalCreated++;\n },\n\n clone: function() {\n var cloned = new this.self; // dependent on 'this'\n\n cloned.groupName = this.statics().speciesName; // equivalent to: My.Cat.speciesName\n\n return cloned;\n }\n});\n\n\nExt.define('My.SnowLeopard', {\n extend: 'My.Cat',\n\n statics: {\n speciesName: 'Snow Leopard' // My.SnowLeopard.speciesName = 'Snow Leopard'\n },\n\n constructor: function() {\n this.callParent();\n }\n});\n\nvar cat = new My.Cat(); // alerts 'Cat', then alerts 'Cat'\n\nvar snowLeopard = new My.SnowLeopard(); // alerts 'Cat', then alerts 'Snow Leopard'\n\nvar clone = snowLeopard.clone();\nalert(Ext.getClassName(clone)); // alerts 'My.SnowLeopard'\nalert(clone.groupName); // alerts 'Cat'\n\nalert(My.Cat.totalCreated); // alerts 3\n
\nAdd methods / properties to the prototype of this class.
\n\nExt.define('My.awesome.Cat', {\n constructor: function() {\n ...\n }\n});\n\n My.awesome.Cat.addMembers({\n meow: function() {\n alert('Meowww...');\n }\n });\n\n var kitty = new My.awesome.Cat;\n kitty.meow();\n
\nAdd / override static properties of this class.
\n\nExt.define('My.cool.Class', {\n ...\n});\n\nMy.cool.Class.addStatics({\n someProperty: 'someValue', // My.cool.Class.someProperty = 'someValue'\n method1: function() { ... }, // My.cool.Class.method1 = function() { ... };\n method2: function() { ... } // My.cool.Class.method2 = function() { ... };\n});\n
\nthis
\nBorrow another class' members to the prototype of this class.
\n\nExt.define('Bank', {\n money: '$$$',\n printMoney: function() {\n alert('$$$$$$$');\n }\n});\n\nExt.define('Thief', {\n ...\n});\n\nThief.borrow(Bank, ['money', 'printMoney']);\n\nvar steve = new Thief();\n\nalert(steve.money); // alerts '$$$'\nsteve.printMoney(); // alerts '$$$$$$$'\n
\nThe class to borrow members from
\nThe names of the members to borrow
\nthis
\nCreate a new instance of this Class.
\n\nExt.define('My.cool.Class', {\n ...\n});\n\nMy.cool.Class.create({\n someConfig: true\n});\n
\n\nAll parameters are passed to the constructor of the class.
\nthe created instance.
\nCreate aliases for existing prototype methods. Example:
\n\nExt.define('My.cool.Class', {\n method1: function() { ... },\n method2: function() { ... }\n});\n\nvar test = new My.cool.Class();\n\nMy.cool.Class.createAlias({\n method3: 'method1',\n method4: 'method2'\n});\n\ntest.method3(); // test.method1()\n\nMy.cool.Class.createAlias('method5', 'method3');\n\ntest.method5(); // test.method3() -> test.method1()\n
\nThe new method name, or an object to set multiple aliases. See\nflexSetter
\nThe original method name
\nGet the current class' name in string format.
\n\nExt.define('My.cool.Class', {\n constructor: function() {\n alert(this.self.getName()); // alerts 'My.cool.Class'\n }\n});\n\nMy.cool.Class.getName(); // 'My.cool.Class'\n
\nclassName
\nAdds members to class.
\nThis method has been deprecated since 4.1
\nUse addMembers instead.
\n\nOverride members of this class. Overridden methods can be invoked via\ncallParent.
\n\nExt.define('My.Cat', {\n constructor: function() {\n alert(\"I'm a cat!\");\n }\n});\n\nMy.Cat.override({\n constructor: function() {\n alert(\"I'm going to be a cat!\");\n\n this.callParent(arguments);\n\n alert(\"Meeeeoooowwww\");\n }\n});\n\nvar kitty = new My.Cat(); // alerts \"I'm going to be a cat!\"\n // alerts \"I'm a cat!\"\n // alerts \"Meeeeoooowwww\"\n
\n\nAs of 4.1, direct use of this method is deprecated. Use Ext.define\ninstead:
\n\nExt.define('My.CatOverride', {\n override: 'My.Cat',\n constructor: function() {\n alert(\"I'm going to be a cat!\");\n\n this.callParent(arguments);\n\n alert(\"Meeeeoooowwww\");\n }\n});\n
\n\nThe above accomplishes the same result but can be managed by the Ext.Loader\nwhich can properly order the override and its target class and the build process\ncan determine whether the override is needed based on the required state of the\ntarget class (My.Cat).
\nThis method has been deprecated since 4.1.0
\nUse Ext.define instead
\n\nThe properties to add to this class. This should be\nspecified as an object literal containing one or more properties.
\nthis class
\n