Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / docs / source / Panel5.html
diff --git a/docs/source/Panel5.html b/docs/source/Panel5.html
new file mode 100644 (file)
index 0000000..f47e393
--- /dev/null
@@ -0,0 +1,477 @@
+<!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-tree.Panel'>/**
+</span> * @class Ext.tree.Panel
+ * @extends Ext.panel.Table
+ * 
+ * The TreePanel provides tree-structured UI representation of tree-structured data.
+ * A TreePanel must be bound to a {@link Ext.data.TreeStore}. TreePanel's support
+ * multiple columns through the {@link columns} configuration. 
+ * 
+ * Simple TreePanel using inline data.
+ *
+ * {@img Ext.tree.Panel/Ext.tree.Panel1.png Ext.tree.Panel component}
+ * 
+ * ## Simple Tree Panel (no columns)
+ *
+ *     var store = Ext.create('Ext.data.TreeStore', {
+ *         root: {
+ *             expanded: true, 
+ *             text:&quot;&quot;,
+ *             user:&quot;&quot;,
+ *             status:&quot;&quot;, 
+ *             children: [
+ *                 { text:&quot;detention&quot;, leaf: true },
+ *                 { text:&quot;homework&quot;, expanded: true, 
+ *                     children: [
+ *                         { text:&quot;book report&quot;, leaf: true },
+ *                         { text:&quot;alegrbra&quot;, leaf: true}
+ *                     ]
+ *                 },
+ *                 { text: &quot;buy lottery tickets&quot;, leaf:true }
+ *             ]
+ *         }
+ *     });     
+ *             
+ *     Ext.create('Ext.tree.Panel', {
+ *         title: 'Simple Tree',
+ *         width: 200,
+ *         height: 150,
+ *         store: store,
+ *         rootVisible: false,        
+ *         renderTo: Ext.getBody()
+ *     });
+ *
+ * @xtype treepanel
+ */
+Ext.define('Ext.tree.Panel', {
+    extend: 'Ext.panel.Table',
+    alias: 'widget.treepanel',
+    alternateClassName: ['Ext.tree.TreePanel', 'Ext.TreePanel'],
+    requires: ['Ext.tree.View', 'Ext.selection.TreeModel', 'Ext.tree.Column'],
+    viewType: 'treeview',
+    selType: 'treemodel',
+    
+    treeCls: Ext.baseCSSPrefix + 'tree-panel',
+    
+<span id='Ext-tree.Panel-cfg-lines'>    /**
+</span>     * @cfg {Boolean} lines false to disable tree lines (defaults to true)
+     */
+    lines: true,
+    
+<span id='Ext-tree.Panel-cfg-useArrows'>    /**
+</span>     * @cfg {Boolean} useArrows true to use Vista-style arrows in the tree (defaults to false)
+     */
+    useArrows: false,
+    
+<span id='Ext-tree.Panel-cfg-singleExpand'>    /**
+</span>     * @cfg {Boolean} singleExpand &lt;tt&gt;true&lt;/tt&gt; if only 1 node per branch may be expanded
+     */
+    singleExpand: false,
+    
+    ddConfig: {
+        enableDrag: true,
+        enableDrop: true
+    },
+    
+<span id='Ext-tree.Panel-cfg-animate'>    /** 
+</span>     * @cfg {Boolean} animate &lt;tt&gt;true&lt;/tt&gt; to enable animated expand/collapse (defaults to the value of {@link Ext#enableFx Ext.enableFx})
+     */
+            
+<span id='Ext-tree.Panel-cfg-rootVisible'>    /** 
+</span>     * @cfg {Boolean} rootVisible &lt;tt&gt;false&lt;/tt&gt; to hide the root node (defaults to &lt;tt&gt;true&lt;/tt&gt;)
+     */
+    rootVisible: true,
+    
+<span id='Ext-tree.Panel-cfg-displayField'>    /** 
+</span>     * @cfg {Boolean} displayField The field inside the model that will be used as the node's text. (defaults to &lt;tt&gt;text&lt;/tt&gt;)
+     */    
+    displayField: 'text',
+
+<span id='Ext-tree.Panel-cfg-root'>    /** 
+</span>     * @cfg {Boolean} root Allows you to not specify a store on this TreePanel. This is useful for creating a simple
+     * tree with preloaded data without having to specify a TreeStore and Model. A store and model will be created and
+     * root will be passed to that store.
+     */
+    root: null,
+    
+    // Required for the Lockable Mixin. These are the configurations which will be copied to the
+    // normal and locked sub tablepanels
+    normalCfgCopy: ['displayField', 'root', 'singleExpand', 'useArrows', 'lines', 'rootVisible', 'scroll'],
+    lockedCfgCopy: ['displayField', 'root', 'singleExpand', 'useArrows', 'lines', 'rootVisible'],
+
+<span id='Ext-tree.Panel-cfg-hideHeaders'>    /**
+</span>     * @cfg {Boolean} hideHeaders
+     * Specify as &lt;code&gt;true&lt;/code&gt; to hide the headers.
+     */
+    
+<span id='Ext-tree.Panel-cfg-folderSort'>    /**
+</span>     * @cfg {Boolean} folderSort Set to true to automatically prepend a leaf sorter to the store (defaults to &lt;tt&gt;undefined&lt;/tt&gt;)
+     */ 
+    
+    constructor: function(config) {
+        config = config || {};
+        if (config.animate === undefined) {
+            config.animate = Ext.enableFx;
+        }
+        this.enableAnimations = config.animate;
+        delete config.animate;
+        
+        this.callParent([config]);
+    },
+    
+    initComponent: function() {
+        var me = this,
+            cls = [me.treeCls];
+
+        if (me.useArrows) {
+            cls.push(Ext.baseCSSPrefix + 'tree-arrows');
+            me.lines = false;
+        }
+        
+        if (me.lines) {
+            cls.push(Ext.baseCSSPrefix + 'tree-lines');
+        } else if (!me.useArrows) {
+            cls.push(Ext.baseCSSPrefix + 'tree-no-lines');
+        }
+
+        if (!me.store || Ext.isObject(me.store) &amp;&amp; !me.store.isStore) {
+            me.store = Ext.create('Ext.data.TreeStore', Ext.apply({}, me.store || {}, {
+                root: me.root,
+                fields: me.fields,
+                model: me.model,
+                folderSort: me.folderSort
+            }));
+        }
+        else if (me.root) {
+            me.store = Ext.data.StoreManager.lookup(me.store);
+            me.store.setRootNode(me.root);
+            if (me.folderSort !== undefined) {
+                me.store.folderSort = me.folderSort;
+                me.store.sort();
+            }            
+        }
+        
+        // I'm not sure if we want to this. It might be confusing
+        // if (me.initialConfig.rootVisible === undefined &amp;&amp; !me.getRootNode()) {
+        //     me.rootVisible = false;
+        // }
+        
+        me.viewConfig = Ext.applyIf(me.viewConfig || {}, {
+            rootVisible: me.rootVisible,
+            animate: me.enableAnimations,
+            singleExpand: me.singleExpand,
+            node: me.store.getRootNode(),
+            hideHeaders: me.hideHeaders
+        });
+        
+        me.mon(me.store, {
+            scope: me,
+            rootchange: me.onRootChange,
+            clear: me.onClear
+        });
+    
+        me.relayEvents(me.store, [
+<span id='Ext-tree.Panel-event-beforeload'>            /**
+</span>             * @event beforeload
+             * Event description
+             * @param {Ext.data.Store} store This Store
+             * @param {Ext.data.Operation} operation The Ext.data.Operation object that will be passed to the Proxy to load the Store
+             */
+            'beforeload',
+
+<span id='Ext-tree.Panel-event-load'>            /**
+</span>             * @event load
+             * Fires whenever the store reads data from a remote data source.
+             * @param {Ext.data.store} this
+             * @param {Array} records An array of records
+             * @param {Boolean} successful True if the operation was successful.
+             */
+            'load'   
+        ]);
+        
+        me.store.on({
+<span id='Ext-tree.Panel-event-itemappend'>            /**
+</span>             * @event itemappend
+             * Fires when a new child node is appended to a node in the tree.
+             * @param {Tree} tree The owner tree
+             * @param {Node} parent The parent node
+             * @param {Node} node The newly appended node
+             * @param {Number} index The index of the newly appended node
+             */
+            append: me.createRelayer('itemappend'),
+            
+<span id='Ext-tree.Panel-event-itemremove'>            /**
+</span>             * @event itemremove
+             * Fires when a child node is removed from a node in the tree
+             * @param {Tree} tree The owner tree
+             * @param {Node} parent The parent node
+             * @param {Node} node The child node removed
+             */
+            remove: me.createRelayer('itemremove'),
+            
+<span id='Ext-tree.Panel-event-itemmove'>            /**
+</span>             * @event itemmove
+             * Fires when a node is moved to a new location in the tree
+             * @param {Tree} tree The owner tree
+             * @param {Node} node The node moved
+             * @param {Node} oldParent The old parent of this node
+             * @param {Node} newParent The new parent of this node
+             * @param {Number} index The index it was moved to
+             */
+            move: me.createRelayer('itemmove'),
+            
+<span id='Ext-tree.Panel-event-iteminsert'>            /**
+</span>             * @event iteminsert
+             * Fires when a new child node is inserted in a node in tree
+             * @param {Tree} tree The owner tree
+             * @param {Node} parent The parent node
+             * @param {Node} node The child node inserted
+             * @param {Node} refNode The child node the node was inserted before
+             */
+            insert: me.createRelayer('iteminsert'),
+            
+<span id='Ext-tree.Panel-event-beforeitemappend'>            /**
+</span>             * @event beforeitemappend
+             * Fires before a new child is appended to a node in this tree, return false to cancel the append.
+             * @param {Tree} tree The owner tree
+             * @param {Node} parent The parent node
+             * @param {Node} node The child node to be appended
+             */
+            beforeappend: me.createRelayer('beforeitemappend'),
+            
+<span id='Ext-tree.Panel-event-beforeitemremove'>            /**
+</span>             * @event beforeitemremove
+             * Fires before a child is removed from a node in this tree, return false to cancel the remove.
+             * @param {Tree} tree The owner tree
+             * @param {Node} parent The parent node
+             * @param {Node} node The child node to be removed
+             */
+            beforeremove: me.createRelayer('beforeitemremove'),
+            
+<span id='Ext-tree.Panel-event-beforeitemmove'>            /**
+</span>             * @event beforeitemmove
+             * Fires before a node is moved to a new location in the tree. Return false to cancel the move.
+             * @param {Tree} tree The owner tree
+             * @param {Node} node The node being moved
+             * @param {Node} oldParent The parent of the node
+             * @param {Node} newParent The new parent the node is moving to
+             * @param {Number} index The index it is being moved to
+             */
+            beforemove: me.createRelayer('beforeitemmove'),
+            
+<span id='Ext-tree.Panel-event-beforeiteminsert'>            /**
+</span>             * @event beforeiteminsert
+             * Fires before a new child is inserted in a node in this tree, return false to cancel the insert.
+             * @param {Tree} tree The owner tree
+             * @param {Node} parent The parent node
+             * @param {Node} node The child node to be inserted
+             * @param {Node} refNode The child node the node is being inserted before
+             */
+            beforeinsert: me.createRelayer('beforeiteminsert'),
+             
+<span id='Ext-tree.Panel-event-itemexpand'>            /**
+</span>             * @event itemexpand
+             * Fires when a node is expanded.
+             * @param {Node} this The expanding node
+             */
+            expand: me.createRelayer('itemexpand'),
+             
+<span id='Ext-tree.Panel-event-itemcollapse'>            /**
+</span>             * @event itemcollapse
+             * Fires when a node is collapsed.
+             * @param {Node} this The collapsing node
+             */
+            collapse: me.createRelayer('itemcollapse'),
+             
+<span id='Ext-tree.Panel-event-beforeitemexpand'>            /**
+</span>             * @event beforeitemexpand
+             * Fires before a node is expanded.
+             * @param {Node} this The expanding node
+             */
+            beforeexpand: me.createRelayer('beforeitemexpand'),
+             
+<span id='Ext-tree.Panel-event-beforeitemcollapse'>            /**
+</span>             * @event beforeitemcollapse
+             * Fires before a node is collapsed.
+             * @param {Node} this The collapsing node
+             */
+            beforecollapse: me.createRelayer('beforeitemcollapse')
+        });
+        
+        // If the user specifies the headers collection manually then dont inject our own
+        if (!me.columns) {
+            if (me.initialConfig.hideHeaders === undefined) {
+                me.hideHeaders = true;
+            }
+            me.columns = [{
+                xtype    : 'treecolumn',
+                text     : 'Name',
+                flex     : 1,
+                dataIndex: me.displayField         
+            }];
+        }
+        
+        if (me.cls) {
+            cls.push(me.cls);
+        }
+        me.cls = cls.join(' ');
+        me.callParent();
+        
+        me.relayEvents(me.getView(), [
+<span id='Ext-tree.Panel-event-checkchange'>            /**
+</span>             * @event checkchange
+             * Fires when a node with a checkbox's checked property changes
+             * @param {Ext.data.Model} node The node who's checked property was changed
+             * @param {Boolean} checked The node's new checked state
+             */
+            'checkchange'
+        ]);
+            
+        // If the root is not visible and there is no rootnode defined, then just lets load the store
+        if (!me.getView().rootVisible &amp;&amp; !me.getRootNode()) {
+            me.setRootNode({
+                expanded: true
+            });
+        }
+    },
+    
+    onClear: function(){
+        this.view.onClear();
+    },
+    
+    setRootNode: function() {
+        return this.store.setRootNode.apply(this.store, arguments);
+    },
+    
+    getRootNode: function() {
+        return this.store.getRootNode();
+    },
+    
+    onRootChange: function(root) {
+        this.view.setRootNode(root);
+    },
+
+<span id='Ext-tree.Panel-method-getChecked'>    /**
+</span>     * Retrieve an array of checked records.
+     * @return {Array} An array containing the checked records
+     */
+    getChecked: function() {
+        return this.getView().getChecked();
+    },
+    
+    isItemChecked: function(rec) {
+        return rec.get('checked');
+    },
+        
+<span id='Ext-tree.Panel-method-expandAll'>    /**
+</span>     * Expand all nodes
+     * @param {Function} callback (optional) A function to execute when the expand finishes.
+     * @param {Object} scope (optional) The scope of the callback function
+     */
+    expandAll : function(callback, scope) {
+        var root = this.getRootNode();
+        if (root) {
+            root.expand(true, callback, scope);
+        }
+    },
+
+<span id='Ext-tree.Panel-method-collapseAll'>    /**
+</span>     * Collapse all nodes
+     * @param {Function} callback (optional) A function to execute when the collapse finishes.
+     * @param {Object} scope (optional) The scope of the callback function
+     */
+    collapseAll : function(callback, scope) {
+        var root = this.getRootNode();
+        if (root) {
+            if (this.getView().rootVisible) {
+                root.collapse(true, callback, scope);
+            }
+            else {
+                root.collapseChildren(true, callback, scope);
+            }
+        }
+    },
+
+<span id='Ext-tree.Panel-method-expandPath'>    /**
+</span>     * Expand the tree to the path of a particular node.
+     * @param {String} path The path to expand
+     * @param {String} field (optional) The field to get the data from. Defaults to the model idProperty.
+     * @param {String} separator (optional) A separator to use. Defaults to &lt;tt&gt;'/'&lt;/tt&gt;.
+     * @param {Function} callback (optional) A function to execute when the expand finishes. The callback will be called with
+     * (success, lastNode) where success is if the expand was successful and lastNode is the last node that was expanded.
+     * @param {Object} scope (optional) The scope of the callback function
+     */
+    expandPath: function(path, field, separator, callback, scope) {
+        var me = this,
+            current = me.getRootNode(),
+            index = 1,
+            view = me.getView(),
+            keys,
+            expander;
+        
+        field = field || me.getRootNode().idProperty;
+        separator = separator || '/';
+        
+        if (Ext.isEmpty(path)) {
+            Ext.callback(callback, scope || me, [false, null]);
+            return;
+        }
+        
+        keys = path.split(separator);
+        if (current.get(field) != keys[1]) {
+            // invalid root
+            Ext.callback(callback, scope || me, [false, current]);
+            return;
+        }
+        
+        expander = function(){
+            if (++index === keys.length) {
+                Ext.callback(callback, scope || me, [true, current]);
+                return;
+            }
+            var node = current.findChild(field, keys[index]);
+            if (!node) {
+                Ext.callback(callback, scope || me, [false, current]);
+                return;
+            }
+            current = node;
+            current.expand(false, expander);
+        };
+        current.expand(false, expander);
+    },
+    
+<span id='Ext-tree.Panel-method-selectPath'>    /**
+</span>     * Expand the tree to the path of a particular node, then selecti t.
+     * @param {String} path The path to select
+     * @param {String} field (optional) The field to get the data from. Defaults to the model idProperty.
+     * @param {String} separator (optional) A separator to use. Defaults to &lt;tt&gt;'/'&lt;/tt&gt;.
+     * @param {Function} callback (optional) A function to execute when the select finishes. The callback will be called with
+     * (bSuccess, oLastNode) where bSuccess is if the select was successful and oLastNode is the last node that was expanded.
+     * @param {Object} scope (optional) The scope of the callback function
+     */
+    selectPath: function(path, field, separator, callback, scope) {
+        var me = this,
+            keys,
+            last;
+        
+        field = field || me.getRootNode().idProperty;
+        separator = separator || '/';
+        
+        keys = path.split(separator);
+        last = keys.pop();
+        
+        me.expandPath(keys.join('/'), field, separator, function(success, node){
+            var doSuccess = false;
+            if (success &amp;&amp; node) {
+                node = node.findChild(field, last);
+                if (node) {
+                    me.getSelectionModel().select(node);
+                    Ext.callback(callback, scope || me, [true, node]);
+                    doSuccess = true;
+                }
+            } else if (node === me.getRootNode()) {
+                doSuccess = true;
+            }
+            Ext.callback(callback, scope || me, [doSuccess, node]);
+        }, me);
+    }
+});</pre></pre></body></html>
\ No newline at end of file