Upgrade to ExtJS 3.2.0 - Released 03/30/2010
[extjs.git] / pkgs / data-list-views-debug.js
1 /*!
2  * Ext JS Library 3.2.0
3  * Copyright(c) 2006-2010 Ext JS, Inc.
4  * licensing@extjs.com
5  * http://www.extjs.com/license
6  */
7 /**
8  * @class Ext.DataView
9  * @extends Ext.BoxComponent
10  * A mechanism for displaying data using custom layout templates and formatting. DataView uses an {@link Ext.XTemplate}
11  * as its internal templating mechanism, and is bound to an {@link Ext.data.Store}
12  * so that as the data in the store changes the view is automatically updated to reflect the changes.  The view also
13  * provides built-in behavior for many common events that can occur for its contained items including click, doubleclick,
14  * mouseover, mouseout, etc. as well as a built-in selection model. <b>In order to use these features, an {@link #itemSelector}
15  * config must be provided for the DataView to determine what nodes it will be working with.</b>
16  *
17  * <p>The example below binds a DataView to a {@link Ext.data.Store} and renders it into an {@link Ext.Panel}.</p>
18  * <pre><code>
19 var store = new Ext.data.JsonStore({
20     url: 'get-images.php',
21     root: 'images',
22     fields: [
23         'name', 'url',
24         {name:'size', type: 'float'},
25         {name:'lastmod', type:'date', dateFormat:'timestamp'}
26     ]
27 });
28 store.load();
29
30 var tpl = new Ext.XTemplate(
31     '&lt;tpl for="."&gt;',
32         '&lt;div class="thumb-wrap" id="{name}"&gt;',
33         '&lt;div class="thumb"&gt;&lt;img src="{url}" title="{name}"&gt;&lt;/div&gt;',
34         '&lt;span class="x-editable"&gt;{shortName}&lt;/span&gt;&lt;/div&gt;',
35     '&lt;/tpl&gt;',
36     '&lt;div class="x-clear"&gt;&lt;/div&gt;'
37 );
38
39 var panel = new Ext.Panel({
40     id:'images-view',
41     frame:true,
42     width:535,
43     autoHeight:true,
44     collapsible:true,
45     layout:'fit',
46     title:'Simple DataView',
47
48     items: new Ext.DataView({
49         store: store,
50         tpl: tpl,
51         autoHeight:true,
52         multiSelect: true,
53         overClass:'x-view-over',
54         itemSelector:'div.thumb-wrap',
55         emptyText: 'No images to display'
56     })
57 });
58 panel.render(document.body);
59 </code></pre>
60  * @constructor
61  * Create a new DataView
62  * @param {Object} config The config object
63  * @xtype dataview
64  */
65 Ext.DataView = Ext.extend(Ext.BoxComponent, {
66     /**
67      * @cfg {String/Array} tpl
68      * The HTML fragment or an array of fragments that will make up the template used by this DataView.  This should
69      * be specified in the same format expected by the constructor of {@link Ext.XTemplate}.
70      */
71     /**
72      * @cfg {Ext.data.Store} store
73      * The {@link Ext.data.Store} to bind this DataView to.
74      */
75     /**
76      * @cfg {String} itemSelector
77      * <b>This is a required setting</b>. A simple CSS selector (e.g. <tt>div.some-class</tt> or 
78      * <tt>span:first-child</tt>) that will be used to determine what nodes this DataView will be
79      * working with.
80      */
81     /**
82      * @cfg {Boolean} multiSelect
83      * True to allow selection of more than one item at a time, false to allow selection of only a single item
84      * at a time or no selection at all, depending on the value of {@link #singleSelect} (defaults to false).
85      */
86     /**
87      * @cfg {Boolean} singleSelect
88      * True to allow selection of exactly one item at a time, false to allow no selection at all (defaults to false).
89      * Note that if {@link #multiSelect} = true, this value will be ignored.
90      */
91     /**
92      * @cfg {Boolean} simpleSelect
93      * True to enable multiselection by clicking on multiple items without requiring the user to hold Shift or Ctrl,
94      * false to force the user to hold Ctrl or Shift to select more than on item (defaults to false).
95      */
96     /**
97      * @cfg {String} overClass
98      * A CSS class to apply to each item in the view on mouseover (defaults to undefined).
99      */
100     /**
101      * @cfg {String} loadingText
102      * A string to display during data load operations (defaults to undefined).  If specified, this text will be
103      * displayed in a loading div and the view's contents will be cleared while loading, otherwise the view's
104      * contents will continue to display normally until the new data is loaded and the contents are replaced.
105      */
106     /**
107      * @cfg {String} selectedClass
108      * A CSS class to apply to each selected item in the view (defaults to 'x-view-selected').
109      */
110     selectedClass : "x-view-selected",
111     /**
112      * @cfg {String} emptyText
113      * The text to display in the view when there is no data to display (defaults to '').
114      */
115     emptyText : "",
116
117     /**
118      * @cfg {Boolean} deferEmptyText True to defer emptyText being applied until the store's first load
119      */
120     deferEmptyText: true,
121     /**
122      * @cfg {Boolean} trackOver True to enable mouseenter and mouseleave events
123      */
124     trackOver: false,
125     
126     /**
127      * @cfg {Boolean} blockRefresh Set this to true to ignore datachanged events on the bound store. This is useful if
128      * you wish to provide custom transition animations via a plugin (defaults to false)
129      */
130     blockRefresh: false,
131
132     //private
133     last: false,
134
135     // private
136     initComponent : function(){
137         Ext.DataView.superclass.initComponent.call(this);
138         if(Ext.isString(this.tpl) || Ext.isArray(this.tpl)){
139             this.tpl = new Ext.XTemplate(this.tpl);
140         }
141
142         this.addEvents(
143             /**
144              * @event beforeclick
145              * Fires before a click is processed. Returns false to cancel the default action.
146              * @param {Ext.DataView} this
147              * @param {Number} index The index of the target node
148              * @param {HTMLElement} node The target node
149              * @param {Ext.EventObject} e The raw event object
150              */
151             "beforeclick",
152             /**
153              * @event click
154              * Fires when a template node is clicked.
155              * @param {Ext.DataView} this
156              * @param {Number} index The index of the target node
157              * @param {HTMLElement} node The target node
158              * @param {Ext.EventObject} e The raw event object
159              */
160             "click",
161             /**
162              * @event mouseenter
163              * Fires when the mouse enters a template node. trackOver:true or an overClass must be set to enable this event.
164              * @param {Ext.DataView} this
165              * @param {Number} index The index of the target node
166              * @param {HTMLElement} node The target node
167              * @param {Ext.EventObject} e The raw event object
168              */
169             "mouseenter",
170             /**
171              * @event mouseleave
172              * Fires when the mouse leaves a template node. trackOver:true or an overClass must be set to enable this event.
173              * @param {Ext.DataView} this
174              * @param {Number} index The index of the target node
175              * @param {HTMLElement} node The target node
176              * @param {Ext.EventObject} e The raw event object
177              */
178             "mouseleave",
179             /**
180              * @event containerclick
181              * Fires when a click occurs and it is not on a template node.
182              * @param {Ext.DataView} this
183              * @param {Ext.EventObject} e The raw event object
184              */
185             "containerclick",
186             /**
187              * @event dblclick
188              * Fires when a template node is double clicked.
189              * @param {Ext.DataView} this
190              * @param {Number} index The index of the target node
191              * @param {HTMLElement} node The target node
192              * @param {Ext.EventObject} e The raw event object
193              */
194             "dblclick",
195             /**
196              * @event contextmenu
197              * Fires when a template node is right clicked.
198              * @param {Ext.DataView} this
199              * @param {Number} index The index of the target node
200              * @param {HTMLElement} node The target node
201              * @param {Ext.EventObject} e The raw event object
202              */
203             "contextmenu",
204             /**
205              * @event containercontextmenu
206              * Fires when a right click occurs that is not on a template node.
207              * @param {Ext.DataView} this
208              * @param {Ext.EventObject} e The raw event object
209              */
210             "containercontextmenu",
211             /**
212              * @event selectionchange
213              * Fires when the selected nodes change.
214              * @param {Ext.DataView} this
215              * @param {Array} selections Array of the selected nodes
216              */
217             "selectionchange",
218
219             /**
220              * @event beforeselect
221              * Fires before a selection is made. If any handlers return false, the selection is cancelled.
222              * @param {Ext.DataView} this
223              * @param {HTMLElement} node The node to be selected
224              * @param {Array} selections Array of currently selected nodes
225              */
226             "beforeselect"
227         );
228
229         this.store = Ext.StoreMgr.lookup(this.store);
230         this.all = new Ext.CompositeElementLite();
231         this.selected = new Ext.CompositeElementLite();
232     },
233
234     // private
235     afterRender : function(){
236         Ext.DataView.superclass.afterRender.call(this);
237
238                 this.mon(this.getTemplateTarget(), {
239             "click": this.onClick,
240             "dblclick": this.onDblClick,
241             "contextmenu": this.onContextMenu,
242             scope:this
243         });
244
245         if(this.overClass || this.trackOver){
246             this.mon(this.getTemplateTarget(), {
247                 "mouseover": this.onMouseOver,
248                 "mouseout": this.onMouseOut,
249                 scope:this
250             });
251         }
252
253         if(this.store){
254             this.bindStore(this.store, true);
255         }
256     },
257
258     /**
259      * Refreshes the view by reloading the data from the store and re-rendering the template.
260      */
261     refresh : function() {
262         this.clearSelections(false, true);
263         var el = this.getTemplateTarget();
264         el.update("");
265         var records = this.store.getRange();
266         if(records.length < 1){
267             if(!this.deferEmptyText || this.hasSkippedEmptyText){
268                 el.update(this.emptyText);
269             }
270             this.all.clear();
271         }else{
272             this.tpl.overwrite(el, this.collectData(records, 0));
273             this.all.fill(Ext.query(this.itemSelector, el.dom));
274             this.updateIndexes(0);
275         }
276         this.hasSkippedEmptyText = true;
277     },
278
279     getTemplateTarget: function(){
280         return this.el;
281     },
282
283     /**
284      * Function which can be overridden to provide custom formatting for each Record that is used by this
285      * DataView's {@link #tpl template} to render each node.
286      * @param {Array/Object} data The raw data object that was used to create the Record.
287      * @param {Number} recordIndex the index number of the Record being prepared for rendering.
288      * @param {Record} record The Record being prepared for rendering.
289      * @return {Array/Object} The formatted data in a format expected by the internal {@link #tpl template}'s overwrite() method.
290      * (either an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'}))
291      */
292     prepareData : function(data){
293         return data;
294     },
295
296     /**
297      * <p>Function which can be overridden which returns the data object passed to this
298      * DataView's {@link #tpl template} to render the whole DataView.</p>
299      * <p>This is usually an Array of data objects, each element of which is processed by an
300      * {@link Ext.XTemplate XTemplate} which uses <tt>'&lt;tpl for="."&gt;'</tt> to iterate over its supplied
301      * data object as an Array. However, <i>named</i> properties may be placed into the data object to
302      * provide non-repeating data such as headings, totals etc.</p>
303      * @param {Array} records An Array of {@link Ext.data.Record}s to be rendered into the DataView.
304      * @param {Number} startIndex the index number of the Record being prepared for rendering.
305      * @return {Array} An Array of data objects to be processed by a repeating XTemplate. May also
306      * contain <i>named</i> properties.
307      */
308     collectData : function(records, startIndex){
309         var r = [];
310         for(var i = 0, len = records.length; i < len; i++){
311             r[r.length] = this.prepareData(records[i].data, startIndex+i, records[i]);
312         }
313         return r;
314     },
315
316     // private
317     bufferRender : function(records){
318         var div = document.createElement('div');
319         this.tpl.overwrite(div, this.collectData(records));
320         return Ext.query(this.itemSelector, div);
321     },
322
323     // private
324     onUpdate : function(ds, record){
325         var index = this.store.indexOf(record);
326         if(index > -1){
327             var sel = this.isSelected(index);
328             var original = this.all.elements[index];
329             var node = this.bufferRender([record], index)[0];
330
331             this.all.replaceElement(index, node, true);
332             if(sel){
333                 this.selected.replaceElement(original, node);
334                 this.all.item(index).addClass(this.selectedClass);
335             }
336             this.updateIndexes(index, index);
337         }
338     },
339
340     // private
341     onAdd : function(ds, records, index){
342         if(this.all.getCount() === 0){
343             this.refresh();
344             return;
345         }
346         var nodes = this.bufferRender(records, index), n, a = this.all.elements;
347         if(index < this.all.getCount()){
348             n = this.all.item(index).insertSibling(nodes, 'before', true);
349             a.splice.apply(a, [index, 0].concat(nodes));
350         }else{
351             n = this.all.last().insertSibling(nodes, 'after', true);
352             a.push.apply(a, nodes);
353         }
354         this.updateIndexes(index);
355     },
356
357     // private
358     onRemove : function(ds, record, index){
359         this.deselect(index);
360         this.all.removeElement(index, true);
361         this.updateIndexes(index);
362         if (this.store.getCount() === 0){
363             this.refresh();
364         }
365     },
366
367     /**
368      * Refreshes an individual node's data from the store.
369      * @param {Number} index The item's data index in the store
370      */
371     refreshNode : function(index){
372         this.onUpdate(this.store, this.store.getAt(index));
373     },
374
375     // private
376     updateIndexes : function(startIndex, endIndex){
377         var ns = this.all.elements;
378         startIndex = startIndex || 0;
379         endIndex = endIndex || ((endIndex === 0) ? 0 : (ns.length - 1));
380         for(var i = startIndex; i <= endIndex; i++){
381             ns[i].viewIndex = i;
382         }
383     },
384     
385     /**
386      * Returns the store associated with this DataView.
387      * @return {Ext.data.Store} The store
388      */
389     getStore : function(){
390         return this.store;
391     },
392
393     /**
394      * Changes the data store bound to this view and refreshes it.
395      * @param {Store} store The store to bind to this view
396      */
397     bindStore : function(store, initial){
398         if(!initial && this.store){
399             if(store !== this.store && this.store.autoDestroy){
400                 this.store.destroy();
401             }else{
402                 this.store.un("beforeload", this.onBeforeLoad, this);
403                 this.store.un("datachanged", this.onDataChanged, this);
404                 this.store.un("add", this.onAdd, this);
405                 this.store.un("remove", this.onRemove, this);
406                 this.store.un("update", this.onUpdate, this);
407                 this.store.un("clear", this.refresh, this);
408             }
409             if(!store){
410                 this.store = null;
411             }
412         }
413         if(store){
414             store = Ext.StoreMgr.lookup(store);
415             store.on({
416                 scope: this,
417                 beforeload: this.onBeforeLoad,
418                 datachanged: this.onDataChanged,
419                 add: this.onAdd,
420                 remove: this.onRemove,
421                 update: this.onUpdate,
422                 clear: this.refresh
423             });
424         }
425         this.store = store;
426         if(store){
427             this.refresh();
428         }
429     },
430     
431     /**
432      * @private
433      * Calls this.refresh if this.blockRefresh is not true
434      */
435     onDataChanged: function() {
436         if (this.blockRefresh !== true) {
437             this.refresh.apply(this, arguments);
438         }
439     },
440
441     /**
442      * Returns the template node the passed child belongs to, or null if it doesn't belong to one.
443      * @param {HTMLElement} node
444      * @return {HTMLElement} The template node
445      */
446     findItemFromChild : function(node){
447         return Ext.fly(node).findParent(this.itemSelector, this.getTemplateTarget());
448     },
449
450     // private
451     onClick : function(e){
452         var item = e.getTarget(this.itemSelector, this.getTemplateTarget());
453         if(item){
454             var index = this.indexOf(item);
455             if(this.onItemClick(item, index, e) !== false){
456                 this.fireEvent("click", this, index, item, e);
457             }
458         }else{
459             if(this.fireEvent("containerclick", this, e) !== false){
460                 this.onContainerClick(e);
461             }
462         }
463     },
464
465     onContainerClick : function(e){
466         this.clearSelections();
467     },
468
469     // private
470     onContextMenu : function(e){
471         var item = e.getTarget(this.itemSelector, this.getTemplateTarget());
472         if(item){
473             this.fireEvent("contextmenu", this, this.indexOf(item), item, e);
474         }else{
475             this.fireEvent("containercontextmenu", this, e);
476         }
477     },
478
479     // private
480     onDblClick : function(e){
481         var item = e.getTarget(this.itemSelector, this.getTemplateTarget());
482         if(item){
483             this.fireEvent("dblclick", this, this.indexOf(item), item, e);
484         }
485     },
486
487     // private
488     onMouseOver : function(e){
489         var item = e.getTarget(this.itemSelector, this.getTemplateTarget());
490         if(item && item !== this.lastItem){
491             this.lastItem = item;
492             Ext.fly(item).addClass(this.overClass);
493             this.fireEvent("mouseenter", this, this.indexOf(item), item, e);
494         }
495     },
496
497     // private
498     onMouseOut : function(e){
499         if(this.lastItem){
500             if(!e.within(this.lastItem, true, true)){
501                 Ext.fly(this.lastItem).removeClass(this.overClass);
502                 this.fireEvent("mouseleave", this, this.indexOf(this.lastItem), this.lastItem, e);
503                 delete this.lastItem;
504             }
505         }
506     },
507
508     // private
509     onItemClick : function(item, index, e){
510         if(this.fireEvent("beforeclick", this, index, item, e) === false){
511             return false;
512         }
513         if(this.multiSelect){
514             this.doMultiSelection(item, index, e);
515             e.preventDefault();
516         }else if(this.singleSelect){
517             this.doSingleSelection(item, index, e);
518             e.preventDefault();
519         }
520         return true;
521     },
522
523     // private
524     doSingleSelection : function(item, index, e){
525         if(e.ctrlKey && this.isSelected(index)){
526             this.deselect(index);
527         }else{
528             this.select(index, false);
529         }
530     },
531
532     // private
533     doMultiSelection : function(item, index, e){
534         if(e.shiftKey && this.last !== false){
535             var last = this.last;
536             this.selectRange(last, index, e.ctrlKey);
537             this.last = last; // reset the last
538         }else{
539             if((e.ctrlKey||this.simpleSelect) && this.isSelected(index)){
540                 this.deselect(index);
541             }else{
542                 this.select(index, e.ctrlKey || e.shiftKey || this.simpleSelect);
543             }
544         }
545     },
546
547     /**
548      * Gets the number of selected nodes.
549      * @return {Number} The node count
550      */
551     getSelectionCount : function(){
552         return this.selected.getCount();
553     },
554
555     /**
556      * Gets the currently selected nodes.
557      * @return {Array} An array of HTMLElements
558      */
559     getSelectedNodes : function(){
560         return this.selected.elements;
561     },
562
563     /**
564      * Gets the indexes of the selected nodes.
565      * @return {Array} An array of numeric indexes
566      */
567     getSelectedIndexes : function(){
568         var indexes = [], s = this.selected.elements;
569         for(var i = 0, len = s.length; i < len; i++){
570             indexes.push(s[i].viewIndex);
571         }
572         return indexes;
573     },
574
575     /**
576      * Gets an array of the selected records
577      * @return {Array} An array of {@link Ext.data.Record} objects
578      */
579     getSelectedRecords : function(){
580         var r = [], s = this.selected.elements;
581         for(var i = 0, len = s.length; i < len; i++){
582             r[r.length] = this.store.getAt(s[i].viewIndex);
583         }
584         return r;
585     },
586
587     /**
588      * Gets an array of the records from an array of nodes
589      * @param {Array} nodes The nodes to evaluate
590      * @return {Array} records The {@link Ext.data.Record} objects
591      */
592     getRecords : function(nodes){
593         var r = [], s = nodes;
594         for(var i = 0, len = s.length; i < len; i++){
595             r[r.length] = this.store.getAt(s[i].viewIndex);
596         }
597         return r;
598     },
599
600     /**
601      * Gets a record from a node
602      * @param {HTMLElement} node The node to evaluate
603      * @return {Record} record The {@link Ext.data.Record} object
604      */
605     getRecord : function(node){
606         return this.store.getAt(node.viewIndex);
607     },
608
609     /**
610      * Clears all selections.
611      * @param {Boolean} suppressEvent (optional) True to skip firing of the selectionchange event
612      */
613     clearSelections : function(suppressEvent, skipUpdate){
614         if((this.multiSelect || this.singleSelect) && this.selected.getCount() > 0){
615             if(!skipUpdate){
616                 this.selected.removeClass(this.selectedClass);
617             }
618             this.selected.clear();
619             this.last = false;
620             if(!suppressEvent){
621                 this.fireEvent("selectionchange", this, this.selected.elements);
622             }
623         }
624     },
625
626     /**
627      * Returns true if the passed node is selected, else false.
628      * @param {HTMLElement/Number/Ext.data.Record} node The node, node index or record to check
629      * @return {Boolean} True if selected, else false
630      */
631     isSelected : function(node){
632         return this.selected.contains(this.getNode(node));
633     },
634
635     /**
636      * Deselects a node.
637      * @param {HTMLElement/Number/Record} node The node, node index or record to deselect
638      */
639     deselect : function(node){
640         if(this.isSelected(node)){
641             node = this.getNode(node);
642             this.selected.removeElement(node);
643             if(this.last == node.viewIndex){
644                 this.last = false;
645             }
646             Ext.fly(node).removeClass(this.selectedClass);
647             this.fireEvent("selectionchange", this, this.selected.elements);
648         }
649     },
650
651     /**
652      * Selects a set of nodes.
653      * @param {Array/HTMLElement/String/Number/Ext.data.Record} nodeInfo An HTMLElement template node, index of a template node,
654      * id of a template node, record associated with a node or an array of any of those to select
655      * @param {Boolean} keepExisting (optional) true to keep existing selections
656      * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
657      */
658     select : function(nodeInfo, keepExisting, suppressEvent){
659         if(Ext.isArray(nodeInfo)){
660             if(!keepExisting){
661                 this.clearSelections(true);
662             }
663             for(var i = 0, len = nodeInfo.length; i < len; i++){
664                 this.select(nodeInfo[i], true, true);
665             }
666             if(!suppressEvent){
667                 this.fireEvent("selectionchange", this, this.selected.elements);
668             }
669         } else{
670             var node = this.getNode(nodeInfo);
671             if(!keepExisting){
672                 this.clearSelections(true);
673             }
674             if(node && !this.isSelected(node)){
675                 if(this.fireEvent("beforeselect", this, node, this.selected.elements) !== false){
676                     Ext.fly(node).addClass(this.selectedClass);
677                     this.selected.add(node);
678                     this.last = node.viewIndex;
679                     if(!suppressEvent){
680                         this.fireEvent("selectionchange", this, this.selected.elements);
681                     }
682                 }
683             }
684         }
685     },
686
687     /**
688      * Selects a range of nodes. All nodes between start and end are selected.
689      * @param {Number} start The index of the first node in the range
690      * @param {Number} end The index of the last node in the range
691      * @param {Boolean} keepExisting (optional) True to retain existing selections
692      */
693     selectRange : function(start, end, keepExisting){
694         if(!keepExisting){
695             this.clearSelections(true);
696         }
697         this.select(this.getNodes(start, end), true);
698     },
699
700     /**
701      * Gets a template node.
702      * @param {HTMLElement/String/Number/Ext.data.Record} nodeInfo An HTMLElement template node, index of a template node, 
703      * the id of a template node or the record associated with the node.
704      * @return {HTMLElement} The node or null if it wasn't found
705      */
706     getNode : function(nodeInfo){
707         if(Ext.isString(nodeInfo)){
708             return document.getElementById(nodeInfo);
709         }else if(Ext.isNumber(nodeInfo)){
710             return this.all.elements[nodeInfo];
711         }else if(nodeInfo instanceof Ext.data.Record){
712             var idx = this.store.indexOf(nodeInfo);
713             return this.all.elements[idx];
714         }
715         return nodeInfo;
716     },
717
718     /**
719      * Gets a range nodes.
720      * @param {Number} start (optional) The index of the first node in the range
721      * @param {Number} end (optional) The index of the last node in the range
722      * @return {Array} An array of nodes
723      */
724     getNodes : function(start, end){
725         var ns = this.all.elements;
726         start = start || 0;
727         end = !Ext.isDefined(end) ? Math.max(ns.length - 1, 0) : end;
728         var nodes = [], i;
729         if(start <= end){
730             for(i = start; i <= end && ns[i]; i++){
731                 nodes.push(ns[i]);
732             }
733         } else{
734             for(i = start; i >= end && ns[i]; i--){
735                 nodes.push(ns[i]);
736             }
737         }
738         return nodes;
739     },
740
741     /**
742      * Finds the index of the passed node.
743      * @param {HTMLElement/String/Number/Record} nodeInfo An HTMLElement template node, index of a template node, the id of a template node
744      * or a record associated with a node.
745      * @return {Number} The index of the node or -1
746      */
747     indexOf : function(node){
748         node = this.getNode(node);
749         if(Ext.isNumber(node.viewIndex)){
750             return node.viewIndex;
751         }
752         return this.all.indexOf(node);
753     },
754
755     // private
756     onBeforeLoad : function(){
757         if(this.loadingText){
758             this.clearSelections(false, true);
759             this.getTemplateTarget().update('<div class="loading-indicator">'+this.loadingText+'</div>');
760             this.all.clear();
761         }
762     },
763
764     onDestroy : function(){
765         this.all.clear();
766         this.selected.clear();
767         Ext.DataView.superclass.onDestroy.call(this);
768         this.bindStore(null);
769     }
770 });
771
772 /**
773  * Changes the data store bound to this view and refreshes it. (deprecated in favor of bindStore)
774  * @param {Store} store The store to bind to this view
775  */
776 Ext.DataView.prototype.setStore = Ext.DataView.prototype.bindStore;
777
778 Ext.reg('dataview', Ext.DataView);
779 /**
780  * @class Ext.list.ListView
781  * @extends Ext.DataView
782  * <p>Ext.list.ListView is a fast and light-weight implentation of a
783  * {@link Ext.grid.GridPanel Grid} like view with the following characteristics:</p>
784  * <div class="mdetail-params"><ul>
785  * <li>resizable columns</li>
786  * <li>selectable</li>
787  * <li>column widths are initially proportioned by percentage based on the container
788  * width and number of columns</li>
789  * <li>uses templates to render the data in any required format</li>
790  * <li>no horizontal scrolling</li>
791  * <li>no editing</li>
792  * </ul></div>
793  * <p>Example usage:</p>
794  * <pre><code>
795 // consume JSON of this form:
796 {
797    "images":[
798       {
799          "name":"dance_fever.jpg",
800          "size":2067,
801          "lastmod":1236974993000,
802          "url":"images\/thumbs\/dance_fever.jpg"
803       },
804       {
805          "name":"zack_sink.jpg",
806          "size":2303,
807          "lastmod":1236974993000,
808          "url":"images\/thumbs\/zack_sink.jpg"
809       }
810    ]
811 }
812 var store = new Ext.data.JsonStore({
813     url: 'get-images.php',
814     root: 'images',
815     fields: [
816         'name', 'url',
817         {name:'size', type: 'float'},
818         {name:'lastmod', type:'date', dateFormat:'timestamp'}
819     ]
820 });
821 store.load();
822
823 var listView = new Ext.list.ListView({
824     store: store,
825     multiSelect: true,
826     emptyText: 'No images to display',
827     reserveScrollOffset: true,
828     columns: [{
829         header: 'File',
830         width: .5,
831         dataIndex: 'name'
832     },{
833         header: 'Last Modified',
834         width: .35,
835         dataIndex: 'lastmod',
836         tpl: '{lastmod:date("m-d h:i a")}'
837     },{
838         header: 'Size',
839         dataIndex: 'size',
840         tpl: '{size:fileSize}', // format using Ext.util.Format.fileSize()
841         align: 'right'
842     }]
843 });
844
845 // put it in a Panel so it looks pretty
846 var panel = new Ext.Panel({
847     id:'images-view',
848     width:425,
849     height:250,
850     collapsible:true,
851     layout:'fit',
852     title:'Simple ListView <i>(0 items selected)</i>',
853     items: listView
854 });
855 panel.render(document.body);
856
857 // little bit of feedback
858 listView.on('selectionchange', function(view, nodes){
859     var l = nodes.length;
860     var s = l != 1 ? 's' : '';
861     panel.setTitle('Simple ListView <i>('+l+' item'+s+' selected)</i>');
862 });
863  * </code></pre>
864  * @constructor
865  * @param {Object} config
866  * @xtype listview
867  */
868 Ext.list.ListView = Ext.extend(Ext.DataView, {
869     /**
870      * Set this property to <tt>true</tt> to disable the header click handler disabling sort
871      * (defaults to <tt>false</tt>).
872      * @type Boolean
873      * @property disableHeaders
874      */
875     /**
876      * @cfg {Boolean} hideHeaders
877      * <tt>true</tt> to hide the {@link #internalTpl header row} (defaults to <tt>false</tt> so
878      * the {@link #internalTpl header row} will be shown).
879      */
880     /**
881      * @cfg {String} itemSelector
882      * Defaults to <tt>'dl'</tt> to work with the preconfigured <b><tt>{@link Ext.DataView#tpl tpl}</tt></b>.
883      * This setting specifies the CSS selector (e.g. <tt>div.some-class</tt> or <tt>span:first-child</tt>)
884      * that will be used to determine what nodes the ListView will be working with.
885      */
886     itemSelector: 'dl',
887     /**
888      * @cfg {String} selectedClass The CSS class applied to a selected row (defaults to
889      * <tt>'x-list-selected'</tt>). An example overriding the default styling:
890     <pre><code>
891     .x-list-selected {background-color: yellow;}
892     </code></pre>
893      * @type String
894      */
895     selectedClass:'x-list-selected',
896     /**
897      * @cfg {String} overClass The CSS class applied when over a row (defaults to
898      * <tt>'x-list-over'</tt>). An example overriding the default styling:
899     <pre><code>
900     .x-list-over {background-color: orange;}
901     </code></pre>
902      * @type String
903      */
904     overClass:'x-list-over',
905     /**
906      * @cfg {Boolean} reserveScrollOffset
907      * By default will defer accounting for the configured <b><tt>{@link #scrollOffset}</tt></b>
908      * for 10 milliseconds.  Specify <tt>true</tt> to account for the configured
909      * <b><tt>{@link #scrollOffset}</tt></b> immediately.
910      */
911     /**
912      * @cfg {Number} scrollOffset The amount of space to reserve for the scrollbar (defaults to
913      * <tt>undefined</tt>). If an explicit value isn't specified, this will be automatically
914      * calculated.
915      */
916     scrollOffset : undefined,
917     /**
918      * @cfg {Boolean/Object} columnResize
919      * Specify <tt>true</tt> or specify a configuration object for {@link Ext.list.ListView.ColumnResizer}
920      * to enable the columns to be resizable (defaults to <tt>true</tt>).
921      */
922     columnResize: true,
923     /**
924      * @cfg {Array} columns An array of column configuration objects, for example:
925      * <pre><code>
926 {
927     align: 'right',
928     dataIndex: 'size',
929     header: 'Size',
930     tpl: '{size:fileSize}',
931     width: .35
932 }
933      * </code></pre>
934      * Acceptable properties for each column configuration object are:
935      * <div class="mdetail-params"><ul>
936      * <li><b><tt>align</tt></b> : String<div class="sub-desc">Set the CSS text-align property
937      * of the column. Defaults to <tt>'left'</tt>.</div></li>
938      * <li><b><tt>dataIndex</tt></b> : String<div class="sub-desc">See {@link Ext.grid.Column}.
939      * {@link Ext.grid.Column#dataIndex dataIndex} for details.</div></li>
940      * <li><b><tt>header</tt></b> : String<div class="sub-desc">See {@link Ext.grid.Column}.
941      * {@link Ext.grid.Column#header header} for details.</div></li>
942      * <li><b><tt>tpl</tt></b> : String<div class="sub-desc">Specify a string to pass as the
943      * configuration string for {@link Ext.XTemplate}.  By default an {@link Ext.XTemplate}
944      * will be implicitly created using the <tt>dataIndex</tt>.</div></li>
945      * <li><b><tt>width</tt></b> : Number<div class="sub-desc">Percentage of the container width
946      * this column should be allocated.  Columns that have no width specified will be
947      * allocated with an equal percentage to fill 100% of the container width.  To easily take
948      * advantage of the full container width, leave the width of at least one column undefined.
949      * Note that if you do not want to take up the full width of the container, the width of
950      * every column needs to be explicitly defined.</div></li>
951      * </ul></div>
952      */
953     /**
954      * @cfg {Boolean/Object} columnSort
955      * Specify <tt>true</tt> or specify a configuration object for {@link Ext.list.ListView.Sorter}
956      * to enable the columns to be sortable (defaults to <tt>true</tt>).
957      */
958     columnSort: true,
959     /**
960      * @cfg {String/Array} internalTpl
961      * The template to be used for the header row.  See {@link #tpl} for more details.
962      */
963
964     /*
965      * IE has issues when setting percentage based widths to 100%. Default to 99.
966      */
967     maxWidth: Ext.isIE ? 99 : 100,
968
969     initComponent : function(){
970         if(this.columnResize){
971             this.colResizer = new Ext.list.ColumnResizer(this.colResizer);
972             this.colResizer.init(this);
973         }
974         if(this.columnSort){
975             this.colSorter = new Ext.list.Sorter(this.columnSort);
976             this.colSorter.init(this);
977         }
978         if(!this.internalTpl){
979             this.internalTpl = new Ext.XTemplate(
980                 '<div class="x-list-header"><div class="x-list-header-inner">',
981                     '<tpl for="columns">',
982                     '<div style="width:{[values.width*100]}%;text-align:{align};"><em unselectable="on" id="',this.id, '-xlhd-{#}">',
983                         '{header}',
984                     '</em></div>',
985                     '</tpl>',
986                     '<div class="x-clear"></div>',
987                 '</div></div>',
988                 '<div class="x-list-body"><div class="x-list-body-inner">',
989                 '</div></div>'
990             );
991         }
992         if(!this.tpl){
993             this.tpl = new Ext.XTemplate(
994                 '<tpl for="rows">',
995                     '<dl>',
996                         '<tpl for="parent.columns">',
997                         '<dt style="width:{[values.width*100]}%;text-align:{align};">',
998                         '<em unselectable="on"<tpl if="cls"> class="{cls}</tpl>">',
999                             '{[values.tpl.apply(parent)]}',
1000                         '</em></dt>',
1001                         '</tpl>',
1002                         '<div class="x-clear"></div>',
1003                     '</dl>',
1004                 '</tpl>'
1005             );
1006         };
1007
1008         var cs = this.columns,
1009             allocatedWidth = 0,
1010             colsWithWidth = 0,
1011             len = cs.length,
1012             columns = [];
1013
1014         for(var i = 0; i < len; i++){
1015             var c = cs[i];
1016             if(!c.isColumn) {
1017                 c.xtype = c.xtype ? (/^lv/.test(c.xtype) ? c.xtype : 'lv' + c.xtype) : 'lvcolumn';
1018                 c = Ext.create(c);
1019             }
1020             if(c.width) {
1021                 allocatedWidth += c.width*100;
1022                 colsWithWidth++;
1023             }
1024             columns.push(c);
1025         }
1026
1027         cs = this.columns = columns;
1028
1029         // auto calculate missing column widths
1030         if(colsWithWidth < len){
1031             var remaining = len - colsWithWidth;
1032             if(allocatedWidth < this.maxWidth){
1033                 var perCol = ((this.maxWidth-allocatedWidth) / remaining)/100;
1034                 for(var j = 0; j < len; j++){
1035                     var c = cs[j];
1036                     if(!c.width){
1037                         c.width = perCol;
1038                     }
1039                 }
1040             }
1041         }
1042         Ext.list.ListView.superclass.initComponent.call(this);
1043     },
1044
1045     onRender : function(){
1046         this.autoEl = {
1047             cls: 'x-list-wrap'
1048         };
1049         Ext.list.ListView.superclass.onRender.apply(this, arguments);
1050
1051         this.internalTpl.overwrite(this.el, {columns: this.columns});
1052
1053         this.innerBody = Ext.get(this.el.dom.childNodes[1].firstChild);
1054         this.innerHd = Ext.get(this.el.dom.firstChild.firstChild);
1055
1056         if(this.hideHeaders){
1057             this.el.dom.firstChild.style.display = 'none';
1058         }
1059     },
1060
1061     getTemplateTarget : function(){
1062         return this.innerBody;
1063     },
1064
1065     /**
1066      * <p>Function which can be overridden which returns the data object passed to this
1067      * view's {@link #tpl template} to render the whole ListView. The returned object
1068      * shall contain the following properties:</p>
1069      * <div class="mdetail-params"><ul>
1070      * <li><b>columns</b> : String<div class="sub-desc">See <tt>{@link #columns}</tt></div></li>
1071      * <li><b>rows</b> : String<div class="sub-desc">See
1072      * <tt>{@link Ext.DataView}.{@link Ext.DataView#collectData collectData}</div></li>
1073      * </ul></div>
1074      * @param {Array} records An Array of {@link Ext.data.Record}s to be rendered into the DataView.
1075      * @param {Number} startIndex the index number of the Record being prepared for rendering.
1076      * @return {Object} A data object containing properties to be processed by a repeating
1077      * XTemplate as described above.
1078      */
1079     collectData : function(){
1080         var rs = Ext.list.ListView.superclass.collectData.apply(this, arguments);
1081         return {
1082             columns: this.columns,
1083             rows: rs
1084         }
1085     },
1086
1087     verifyInternalSize : function(){
1088         if(this.lastSize){
1089             this.onResize(this.lastSize.width, this.lastSize.height);
1090         }
1091     },
1092
1093     // private
1094     onResize : function(w, h){
1095         var bd = this.innerBody.dom;
1096         var hd = this.innerHd.dom;
1097         if(!bd){
1098             return;
1099         }
1100         var bdp = bd.parentNode;
1101         if(Ext.isNumber(w)){
1102             var sw = w - Ext.num(this.scrollOffset, Ext.getScrollBarWidth());
1103             if(this.reserveScrollOffset || ((bdp.offsetWidth - bdp.clientWidth) > 10)){
1104                 bd.style.width = sw + 'px';
1105                 hd.style.width = sw + 'px';
1106             }else{
1107                 bd.style.width = w + 'px';
1108                 hd.style.width = w + 'px';
1109                 setTimeout(function(){
1110                     if((bdp.offsetWidth - bdp.clientWidth) > 10){
1111                         bd.style.width = sw + 'px';
1112                         hd.style.width = sw + 'px';
1113                     }
1114                 }, 10);
1115             }
1116         }
1117         if(Ext.isNumber(h)){
1118             bdp.style.height = (h - hd.parentNode.offsetHeight) + 'px';
1119         }
1120     },
1121
1122     updateIndexes : function(){
1123         Ext.list.ListView.superclass.updateIndexes.apply(this, arguments);
1124         this.verifyInternalSize();
1125     },
1126
1127     findHeaderIndex : function(hd){
1128         hd = hd.dom || hd;
1129         var pn = hd.parentNode, cs = pn.parentNode.childNodes;
1130         for(var i = 0, c; c = cs[i]; i++){
1131             if(c == pn){
1132                 return i;
1133             }
1134         }
1135         return -1;
1136     },
1137
1138     setHdWidths : function(){
1139         var els = this.innerHd.dom.getElementsByTagName('div');
1140         for(var i = 0, cs = this.columns, len = cs.length; i < len; i++){
1141             els[i].style.width = (cs[i].width*100) + '%';
1142         }
1143     }
1144 });
1145
1146 Ext.reg('listview', Ext.list.ListView);
1147
1148 // Backwards compatibility alias
1149 Ext.ListView = Ext.list.ListView;/**
1150  * @class Ext.list.Column
1151  * <p>This class encapsulates column configuration data to be used in the initialization of a
1152  * {@link Ext.list.ListView ListView}.</p>
1153  * <p>While subclasses are provided to render data in different ways, this class renders a passed
1154  * data field unchanged and is usually used for textual columns.</p>
1155  */
1156 Ext.list.Column = Ext.extend(Object, {
1157     /**
1158      * @private
1159      * @cfg {Boolean} isColumn
1160      * Used by ListView constructor method to avoid reprocessing a Column
1161      * if <code>isColumn</code> is not set ListView will recreate a new Ext.list.Column
1162      * Defaults to true.
1163      */
1164     isColumn: true,
1165     
1166     /**
1167      * @cfg {String} align
1168      * Set the CSS text-align property of the column. Defaults to <tt>'left'</tt>.
1169      */        
1170     align: 'left',
1171     /**
1172      * @cfg {String} header Optional. The header text to be used as innerHTML
1173      * (html tags are accepted) to display in the ListView.  <b>Note</b>: to
1174      * have a clickable header with no text displayed use <tt>'&#160;'</tt>.
1175      */    
1176     header: '',
1177     
1178     /**
1179      * @cfg {Number} width Optional. Percentage of the container width
1180      * this column should be allocated.  Columns that have no width specified will be
1181      * allocated with an equal percentage to fill 100% of the container width.  To easily take
1182      * advantage of the full container width, leave the width of at least one column undefined.
1183      * Note that if you do not want to take up the full width of the container, the width of
1184      * every column needs to be explicitly defined.
1185      */    
1186     width: null,
1187
1188     /**
1189      * @cfg {String} cls Optional. This option can be used to add a CSS class to the cell of each
1190      * row for this column.
1191      */
1192     cls: '',
1193     
1194     /**
1195      * @cfg {String} tpl Optional. Specify a string to pass as the
1196      * configuration string for {@link Ext.XTemplate}.  By default an {@link Ext.XTemplate}
1197      * will be implicitly created using the <tt>dataIndex</tt>.
1198      */
1199
1200     /**
1201      * @cfg {String} dataIndex <p><b>Required</b>. The name of the field in the
1202      * ListViews's {@link Ext.data.Store}'s {@link Ext.data.Record} definition from
1203      * which to draw the column's value.</p>
1204      */
1205     
1206     constructor : function(c){
1207         if(!c.tpl){
1208             c.tpl = new Ext.XTemplate('{' + c.dataIndex + '}');
1209         }
1210         else if(Ext.isString(c.tpl)){
1211             c.tpl = new Ext.XTemplate(c.tpl);
1212         }
1213         
1214         Ext.apply(this, c);
1215     }
1216 });
1217
1218 Ext.reg('lvcolumn', Ext.list.Column);
1219
1220 /**
1221  * @class Ext.list.NumberColumn
1222  * @extends Ext.list.Column
1223  * <p>A Column definition class which renders a numeric data field according to a {@link #format} string.  See the
1224  * {@link Ext.list.Column#xtype xtype} config option of {@link Ext.list.Column} for more details.</p>
1225  */
1226 Ext.list.NumberColumn = Ext.extend(Ext.list.Column, {
1227     /**
1228      * @cfg {String} format
1229      * A formatting string as used by {@link Ext.util.Format#number} to format a numeric value for this Column
1230      * (defaults to <tt>'0,000.00'</tt>).
1231      */    
1232     format: '0,000.00',
1233     
1234     constructor : function(c) {
1235         c.tpl = c.tpl || new Ext.XTemplate('{' + c.dataIndex + ':number("' + (c.format || this.format) + '")}');       
1236         Ext.list.NumberColumn.superclass.constructor.call(this, c);
1237     }
1238 });
1239
1240 Ext.reg('lvnumbercolumn', Ext.list.NumberColumn);
1241
1242 /**
1243  * @class Ext.list.DateColumn
1244  * @extends Ext.list.Column
1245  * <p>A Column definition class which renders a passed date according to the default locale, or a configured
1246  * {@link #format}. See the {@link Ext.list.Column#xtype xtype} config option of {@link Ext.list.Column}
1247  * for more details.</p>
1248  */
1249 Ext.list.DateColumn = Ext.extend(Ext.list.Column, {
1250     format: 'm/d/Y',
1251     constructor : function(c) {
1252         c.tpl = c.tpl || new Ext.XTemplate('{' + c.dataIndex + ':date("' + (c.format || this.format) + '")}');      
1253         Ext.list.DateColumn.superclass.constructor.call(this, c);
1254     }
1255 });
1256 Ext.reg('lvdatecolumn', Ext.list.DateColumn);
1257
1258 /**
1259  * @class Ext.list.BooleanColumn
1260  * @extends Ext.list.Column
1261  * <p>A Column definition class which renders boolean data fields.  See the {@link Ext.list.Column#xtype xtype}
1262  * config option of {@link Ext.list.Column} for more details.</p>
1263  */
1264 Ext.list.BooleanColumn = Ext.extend(Ext.list.Column, {
1265     /**
1266      * @cfg {String} trueText
1267      * The string returned by the renderer when the column value is not falsey (defaults to <tt>'true'</tt>).
1268      */
1269     trueText: 'true',
1270     /**
1271      * @cfg {String} falseText
1272      * The string returned by the renderer when the column value is falsey (but not undefined) (defaults to
1273      * <tt>'false'</tt>).
1274      */
1275     falseText: 'false',
1276     /**
1277      * @cfg {String} undefinedText
1278      * The string returned by the renderer when the column value is undefined (defaults to <tt>'&#160;'</tt>).
1279      */
1280     undefinedText: '&#160;',
1281     
1282     constructor : function(c) {
1283         c.tpl = c.tpl || new Ext.XTemplate('{' + c.dataIndex + ':this.format}');
1284         
1285         var t = this.trueText, f = this.falseText, u = this.undefinedText;
1286         c.tpl.format = function(v){
1287             if(v === undefined){
1288                 return u;
1289             }
1290             if(!v || v === 'false'){
1291                 return f;
1292             }
1293             return t;
1294         };
1295         
1296         Ext.list.DateColumn.superclass.constructor.call(this, c);
1297     }
1298 });
1299
1300 Ext.reg('lvbooleancolumn', Ext.list.BooleanColumn);/**
1301  * @class Ext.list.ColumnResizer
1302  * @extends Ext.util.Observable
1303  * <p>Supporting Class for Ext.list.ListView</p>
1304  * @constructor
1305  * @param {Object} config
1306  */
1307 Ext.list.ColumnResizer = Ext.extend(Ext.util.Observable, {
1308     /**
1309      * @cfg {Number} minPct The minimum percentage to allot for any column (defaults to <tt>.05</tt>)
1310      */
1311     minPct: .05,
1312
1313     constructor: function(config){
1314         Ext.apply(this, config);
1315         Ext.list.ColumnResizer.superclass.constructor.call(this);
1316     },
1317     init : function(listView){
1318         this.view = listView;
1319         listView.on('render', this.initEvents, this);
1320     },
1321
1322     initEvents : function(view){
1323         view.mon(view.innerHd, 'mousemove', this.handleHdMove, this);
1324         this.tracker = new Ext.dd.DragTracker({
1325             onBeforeStart: this.onBeforeStart.createDelegate(this),
1326             onStart: this.onStart.createDelegate(this),
1327             onDrag: this.onDrag.createDelegate(this),
1328             onEnd: this.onEnd.createDelegate(this),
1329             tolerance: 3,
1330             autoStart: 300
1331         });
1332         this.tracker.initEl(view.innerHd);
1333         view.on('beforedestroy', this.tracker.destroy, this.tracker);
1334     },
1335
1336     handleHdMove : function(e, t){
1337         var hw = 5,
1338             x = e.getPageX(),
1339             hd = e.getTarget('em', 3, true);
1340         if(hd){
1341             var r = hd.getRegion(),
1342                 ss = hd.dom.style,
1343                 pn = hd.dom.parentNode;
1344
1345             if(x - r.left <= hw && pn != pn.parentNode.firstChild){
1346                 this.activeHd = Ext.get(pn.previousSibling.firstChild);
1347                 ss.cursor = Ext.isWebKit ? 'e-resize' : 'col-resize';
1348             } else if(r.right - x <= hw && pn != pn.parentNode.lastChild.previousSibling){
1349                 this.activeHd = hd;
1350                 ss.cursor = Ext.isWebKit ? 'w-resize' : 'col-resize';
1351             } else{
1352                 delete this.activeHd;
1353                 ss.cursor = '';
1354             }
1355         }
1356     },
1357
1358     onBeforeStart : function(e){
1359         this.dragHd = this.activeHd;
1360         return !!this.dragHd;
1361     },
1362
1363     onStart: function(e){
1364         this.view.disableHeaders = true;
1365         this.proxy = this.view.el.createChild({cls:'x-list-resizer'});
1366         this.proxy.setHeight(this.view.el.getHeight());
1367
1368         var x = this.tracker.getXY()[0],
1369             w = this.view.innerHd.getWidth();
1370
1371         this.hdX = this.dragHd.getX();
1372         this.hdIndex = this.view.findHeaderIndex(this.dragHd);
1373
1374         this.proxy.setX(this.hdX);
1375         this.proxy.setWidth(x-this.hdX);
1376
1377         this.minWidth = w*this.minPct;
1378         this.maxWidth = w - (this.minWidth*(this.view.columns.length-1-this.hdIndex));
1379     },
1380
1381     onDrag: function(e){
1382         var cursorX = this.tracker.getXY()[0];
1383         this.proxy.setWidth((cursorX-this.hdX).constrain(this.minWidth, this.maxWidth));
1384     },
1385
1386     onEnd: function(e){
1387         /* calculate desired width by measuring proxy and then remove it */
1388         var nw = this.proxy.getWidth();
1389         this.proxy.remove();
1390
1391         var index = this.hdIndex,
1392             vw = this.view,
1393             cs = vw.columns,
1394             len = cs.length,
1395             w = this.view.innerHd.getWidth(),
1396             minPct = this.minPct * 100,
1397             pct = Math.ceil((nw * vw.maxWidth) / w),
1398             diff = (cs[index].width * 100) - pct,
1399             eachItem = Math.floor(diff / (len-1-index)),
1400             mod = diff - (eachItem * (len-1-index));
1401
1402         for(var i = index+1; i < len; i++){
1403             var cw = (cs[i].width * 100) + eachItem,
1404                 ncw = Math.max(minPct, cw);
1405             if(cw != ncw){
1406                 mod += cw - ncw;
1407             }
1408             cs[i].width = ncw / 100;
1409         }
1410         cs[index].width = pct / 100;
1411         cs[index+1].width += (mod / 100);
1412         delete this.dragHd;
1413         vw.setHdWidths();
1414         vw.refresh();
1415         setTimeout(function(){
1416             vw.disableHeaders = false;
1417         }, 100);
1418     }
1419 });
1420
1421 // Backwards compatibility alias
1422 Ext.ListView.ColumnResizer = Ext.list.ColumnResizer;/**
1423  * @class Ext.list.Sorter
1424  * @extends Ext.util.Observable
1425  * <p>Supporting Class for Ext.list.ListView</p>
1426  * @constructor
1427  * @param {Object} config
1428  */
1429 Ext.list.Sorter = Ext.extend(Ext.util.Observable, {
1430     /**
1431      * @cfg {Array} sortClasses
1432      * The CSS classes applied to a header when it is sorted. (defaults to <tt>["sort-asc", "sort-desc"]</tt>)
1433      */
1434     sortClasses : ["sort-asc", "sort-desc"],
1435
1436     constructor: function(config){
1437         Ext.apply(this, config);
1438         Ext.list.Sorter.superclass.constructor.call(this);
1439     },
1440
1441     init : function(listView){
1442         this.view = listView;
1443         listView.on('render', this.initEvents, this);
1444     },
1445
1446     initEvents : function(view){
1447         view.mon(view.innerHd, 'click', this.onHdClick, this);
1448         view.innerHd.setStyle('cursor', 'pointer');
1449         view.mon(view.store, 'datachanged', this.updateSortState, this);
1450         this.updateSortState.defer(10, this, [view.store]);
1451     },
1452
1453     updateSortState : function(store){
1454         var state = store.getSortState();
1455         if(!state){
1456             return;
1457         }
1458         this.sortState = state;
1459         var cs = this.view.columns, sortColumn = -1;
1460         for(var i = 0, len = cs.length; i < len; i++){
1461             if(cs[i].dataIndex == state.field){
1462                 sortColumn = i;
1463                 break;
1464             }
1465         }
1466         if(sortColumn != -1){
1467             var sortDir = state.direction;
1468             this.updateSortIcon(sortColumn, sortDir);
1469         }
1470     },
1471
1472     updateSortIcon : function(col, dir){
1473         var sc = this.sortClasses;
1474         var hds = this.view.innerHd.select('em').removeClass(sc);
1475         hds.item(col).addClass(sc[dir == "DESC" ? 1 : 0]);
1476     },
1477
1478     onHdClick : function(e){
1479         var hd = e.getTarget('em', 3);
1480         if(hd && !this.view.disableHeaders){
1481             var index = this.view.findHeaderIndex(hd);
1482             this.view.store.sort(this.view.columns[index].dataIndex);
1483         }
1484     }
1485 });
1486
1487 // Backwards compatibility alias
1488 Ext.ListView.Sorter = Ext.list.Sorter;