8

I've been working with ExtJS for a good few months now, but still don't have a perfectly clear map of what's going on behind the scenes there. I'm just talking about the building blocks of the framework and their most basic functionality.

  • Ext.Component
  • Ext.Element
  • DOM.Element
  • DOM.Node (?)
  • CompositeElement (?)
  • Whatever else (?)

For each of the abovementioned I would like to know:

  1. How to select: by ID, by class, via parent, find (OR children OR query OR select? WTF), siblings, ComponentQuery, DOM-query, CSS-query, etc..

  2. How to manipulate in the tree: create, append, prepend, insert after this sibling, move to that parent, remove, destroy, etc..

  3. How to manipulate on the screen: show, hide, fade, slide, move up, down, change size, etc..

  4. How to identify related to each other: find DOM.Element knowing its Ext.Component, find Ext.Component knowing its DOM.Element, etc..

  5. What is the dependency between them: what happens to the DOM.Element if its Ext.Component is hidden / destroyed / changed / moved, what happens to the Ext.Component if its Ext.Element is hidden / destroyed / changed / moved, etc.

I'm looking for a methodical and logically clear layout of how each is supposed to be used and is expected to behave. I am also hoping that the described functionality can be grouped in corresponding categories, e.g. would be nice to see complement traversing methods .up() and .down() next to each other, rather than alphabetically pages apart. Of course links and examples (which the official documentation lacks so badly) are also welcome!

Geo
  • 12,666
  • 4
  • 40
  • 55
  • 2
    I think your question is too broad, if you have a specific question about functionality, or things you don't understand from the documentation, but you've basically just asked "how does the whole core work". It seems as though you haven't spent enough time reading the documentation. – Evan Trimboli Sep 16 '13 at 23:51
  • Potentially this question could turn into a community wiki. The documentation lacks examples of use and clean distinguishing between each object. Perhaps you are right though. Maybe it would make sense to split it into 5 questions: one for each number? – Geo Sep 17 '13 at 15:04
  • Or one for each object? – Geo Sep 17 '13 at 15:37
  • No answers are full enough. I wished bounty could be postponed for a more comprehensive answer. I will start a new one, once I rack up some more reputation points! – Geo Sep 20 '13 at 14:35

3 Answers3

7

You can find out a whole lot about the building blocks of ExtJS (known as Ext Core) from the manual for this: http://docs.sencha.com/core/manual/. I will try to add some knowledge and highlight some key points, but you should definitely read through that for a very informative overview.

Ext.Component
The building block for the OOP paradigm within ExtJS. Essentially, this is an Object that contains inherited functionality to serve as the basis for a specialized component that will be transformed by the framework into DOM elements that are shown as HTML.

The Sencha documentation is excellent for this. Here are a couple good places to start: http://docs.sencha.com/extjs/4.2.1/#!/guide/layouts_and_containers http://docs.sencha.com/extjs/4.2.1/#!/guide/components

Ext.Element vs DOM Element
As an JavaScript develop knows, a DOM element is just a JS object that represents a tag in the document's HTML. Essentially, Ext.Element is a wrapper object for a DOM element that allows for ExtJS to manipulate the object. Any DOM element on the page can be wrapped as an Ext.Element to allow for this additional functionality.

For example, take this HTML tag:

<div id="myDiv">My content</div>

You can access this using

var el = document.getElementById('myDiv')

and use the basic, built-in JavaScript DOM functionality on el. You could also access this using

var el = Ext.get('myDiv')

and have a whole additional set of functionality available to apply to that element using the ExtJS library

The Sencha docs are also excellent for this. See all the available functionality for Ext.Element here: http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.dom.Element

Misc
You can get an Ext.Element from a component using the getEl() method:

var myComponent = Ext.create('Ext.Component', { html: 'my component' });
var el = myComponent.getEl();

You would rarely need to go the other way, to determine a component from a DOM element. There isn't much of a use case there unless you are really hacking something. A major reason for using a framework like ExtJS is to prevent needing to do something like this; if should develop entirely within the JavaScript, you should be able to avoid having a reference to a DOM element where you need to get its containing ExtJS component.

Niklas answered pretty well about how to select components and elements. The only things I would really add is that you can use up() and down() to select relative to a component. In this way, you should use itemId on components rather than the global identifier id (using id can cause difficult-to-debug errors if you are reusing components with the same ID).

Also, to add to Niklas's answer about showing/hiding components, the framework does indeed add some CSS to the component's element, depending on what the hideMode for the component is. Learn more about that property here: http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.AbstractComponent-cfg-hideMode

An excellent way to learn more is to look through all of the examples that come packaged with the framework. Open the examples in your browser, then look through the code to find out how things are done. You will find it way easier to learn this way, rather than reading it on paper or a website. Nothing beats experience when it comes to learning something new.

kevhender
  • 4,285
  • 1
  • 13
  • 16
  • Thank you for the 'core' link - super useful! – Geo Sep 25 '13 at 17:43
  • Yeah, I don't know why that one is so hard to find, and not advertised well... it has a wealth of great info. – kevhender Sep 25 '13 at 17:57
  • It is. I just hope it's not too outdated. As I'm reading along if find typos/errors, and I don't see a clear way to report/comment them. – Geo Sep 25 '13 at 18:15
2

How to select: by ID, by class, via parent, find (OR children OR query OR select? WTF), siblings, ComponentQuery, DOM-query, CSS-query, etc..

Ext.ComponentQuery.query("*")                   // get all
Ext.ComponentQuery.query("button")              // all buttons
Ext.ComponentQuery.query("#myid")               // all controls / components myid
Ext.ComponentQuery.query("#myid", rootelement)  // all controls / components myid with rootelement
Ext.ComponentQuery.query("#myid,button")        // all buttons or controls / components myid

How to manipulate in the tree: create, append, prepend, insert after this sibling, move to that parent, remove, destroy, etc..

Adding button to a View:

Ext.ComponentQuery.query("#viewId")[0].add(new Ext.Button({ text: 'test'}));

There is also insert, remove and so on depending on the control you are querying.

How to manipulate on the screen: show, hide, fade, slide, move up, down, change size, etc..

Ext.ComponentQuery.query("button").forEach(function(button){ button.hide(); })      // hide all buttons

There is also show, disable, enable and so on depending on the control you are querying.

How to identify related to each other: find DOM.Element knowing its Ext.Component, find Ext.Component knowing its DOM.Element, etc..

Finding Ext.Component knowing its Dom.Element is pretty easy, you just take the ID from the DOM element and use Ext.ComponentQuery.query("#id"). There is also Ext.select('#id') for getting the object from an ID.

With the element property you can get the DOM:

var dom = Ext.ComponentQuery.query("button")[0].element.dom // Getting the DOM from the first button
var dom2 = component.element.dom                            // does also work as long as component is a valid sencha touch component

What is the dependency between them: what happens to the DOM.Element if its Ext.Component is hidden / destroyed / changed / moved, what happens to the Ext.Component if its Ext.Element is hidden / destroyed / changed / moved, etc.

I think, I'm not sure, that if you call .hide for instance there will be some CSS applied to the DOM for example: display: none. Internally they can use some framework like jQuery for that or the old school version document.getElementById('id').css and so one. If you call .show, it may change to display: block or whatever type it was before(this could be saved in the Sencha Touch class).

I don't know what happens if the DOM element gets destroyed. Probably the element too and then the garbage collector has some work to do.

If there are any more questions / something was unclear or not enough, don't hesitate to ask.

Niklas
  • 23,674
  • 33
  • 131
  • 170
  • This is a very solid try. However, it seems to be only discussing `Ext.ComponentQuery.query`. How about elements, DOM nodes, etc.? Also it might need a bit of a clean up with layout (I maybe will edit this answer myself later) – Geo Sep 16 '13 at 15:08
  • 1
    The thing is you can do a lot of stuff with `Ext.ComponentQuery.query`. Normally you don't care about elements and DOM nodes if you develop with Sencha Touch, because you let Sencha Touch do the stuff with the dom. Let me know, when you edited your questions. – Niklas Sep 16 '13 at 16:47
  • The way you answered is in the right direction, but I would also want to know the same about related Ext.Elements, DOM nodes, and what even the difference between them. If, like you say, I shouldn't care about those, then at least I have to know how to reach them, what the dependencies are, etc. – Geo Sep 17 '13 at 15:36
  • 1
    Well, you now at least now how to reach them but even that is not really necessary. `Ext.Element` is something Sencha Touch related and a DOM node can bascially be everything in your browser. There are DOM Objects for links, text, from controls etc. In the end every Sencha Touch Element will be translated to pure HTML, since the browser / device only know how to display HTML. For instance `textview` will be something like `` with some specific Sencha Touch classes for the typical design and packed into some divs for the layout. – Niklas Sep 17 '13 at 16:27
1

An attempt to answer the question myself.

Since there is no TABLE markup support on this website, I put my answer in this shared Spreadsheet. Note the comments on mouse rollover.

It's just a pattern for now. It needs work to get more legible and complete. Feel free to comment, or ask me if you would like to edit it.

Community
  • 1
  • 1
Geo
  • 12,666
  • 4
  • 40
  • 55
  • You forgot: [nextNode([selector])](http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.AbstractComponent-method-nextNode) / [previousNode([selector])](http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.AbstractComponent-method-previousNode) and [ownerCt](http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.AbstractComponent-property-ownerCt) – sra Sep 20 '13 at 05:45
  • Well I corrected and updated your Table please see the [new Version](http://jsfiddle.net/D2JGf/3/) – sra Sep 20 '13 at 06:08
  • @sra and how am I supposed to award the bounty? I wished it could be postponed – Geo Sep 20 '13 at 13:50
  • you can't award the bounty to yourself – what is sleep Sep 20 '13 at 14:01