3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.com/license
15 <div id="cls-Ext.list.ListView"></div>/**
16 * @class Ext.list.ListView
17 * @extends Ext.DataView
18 * <p>Ext.list.ListView is a fast and light-weight implentation of a
19 * {@link Ext.grid.GridPanel Grid} like view with the following characteristics:</p>
20 * <div class="mdetail-params"><ul>
21 * <li>resizable columns</li>
23 * <li>column widths are initially proportioned by percentage based on the container
24 * width and number of columns</li>
25 * <li>uses templates to render the data in any required format</li>
26 * <li>no horizontal scrolling</li>
29 * <p>Example usage:</p>
31 // consume JSON of this form:
35 "name":"dance_fever.jpg",
37 "lastmod":1236974993000,
38 "url":"images\/thumbs\/dance_fever.jpg"
41 "name":"zack_sink.jpg",
43 "lastmod":1236974993000,
44 "url":"images\/thumbs\/zack_sink.jpg"
48 var store = new Ext.data.JsonStore({
49 url: 'get-images.php',
53 {name:'size', type: 'float'},
54 {name:'lastmod', type:'date', dateFormat:'timestamp'}
59 var listView = new Ext.list.ListView({
62 emptyText: 'No images to display',
63 reserveScrollOffset: true,
69 header: 'Last Modified',
72 tpl: '{lastmod:date("m-d h:i a")}'
76 tpl: '{size:fileSize}', // format using Ext.util.Format.fileSize()
81 // put it in a Panel so it looks pretty
82 var panel = new Ext.Panel({
88 title:'Simple ListView <i>(0 items selected)</i>',
91 panel.render(document.body);
93 // little bit of feedback
94 listView.on('selectionchange', function(view, nodes){
96 var s = l != 1 ? 's' : '';
97 panel.setTitle('Simple ListView <i>('+l+' item'+s+' selected)</i>');
101 * @param {Object} config
104 Ext.list.ListView = Ext.extend(Ext.DataView, {
105 <div id="prop-Ext.list.ListView-disableHeaders"></div>/**
106 * Set this property to <tt>true</tt> to disable the header click handler disabling sort
107 * (defaults to <tt>false</tt>).
109 * @property disableHeaders
111 <div id="cfg-Ext.list.ListView-hideHeaders"></div>/**
112 * @cfg {Boolean} hideHeaders
113 * <tt>true</tt> to hide the {@link #internalTpl header row} (defaults to <tt>false</tt> so
114 * the {@link #internalTpl header row} will be shown).
116 <div id="cfg-Ext.list.ListView-itemSelector"></div>/**
117 * @cfg {String} itemSelector
118 * Defaults to <tt>'dl'</tt> to work with the preconfigured <b><tt>{@link Ext.DataView#tpl tpl}</tt></b>.
119 * This setting specifies the CSS selector (e.g. <tt>div.some-class</tt> or <tt>span:first-child</tt>)
120 * that will be used to determine what nodes the ListView will be working with.
123 <div id="cfg-Ext.list.ListView-selectedClass"></div>/**
124 * @cfg {String} selectedClass The CSS class applied to a selected row (defaults to
125 * <tt>'x-list-selected'</tt>). An example overriding the default styling:
127 .x-list-selected {background-color: yellow;}
131 selectedClass:'x-list-selected',
132 <div id="cfg-Ext.list.ListView-overClass"></div>/**
133 * @cfg {String} overClass The CSS class applied when over a row (defaults to
134 * <tt>'x-list-over'</tt>). An example overriding the default styling:
136 .x-list-over {background-color: orange;}
140 overClass:'x-list-over',
141 <div id="cfg-Ext.list.ListView-reserveScrollOffset"></div>/**
142 * @cfg {Boolean} reserveScrollOffset
143 * By default will defer accounting for the configured <b><tt>{@link #scrollOffset}</tt></b>
144 * for 10 milliseconds. Specify <tt>true</tt> to account for the configured
145 * <b><tt>{@link #scrollOffset}</tt></b> immediately.
147 <div id="cfg-Ext.list.ListView-scrollOffset"></div>/**
148 * @cfg {Number} scrollOffset The amount of space to reserve for the scrollbar (defaults to
149 * <tt>undefined</tt>). If an explicit value isn't specified, this will be automatically
152 scrollOffset : undefined,
153 <div id="cfg-Ext.list.ListView-columnResize"></div>/**
154 * @cfg {Boolean/Object} columnResize
155 * Specify <tt>true</tt> or specify a configuration object for {@link Ext.list.ListView.ColumnResizer}
156 * to enable the columns to be resizable (defaults to <tt>true</tt>).
159 <div id="cfg-Ext.list.ListView-columns"></div>/**
160 * @cfg {Array} columns An array of column configuration objects, for example:
166 tpl: '{size:fileSize}',
170 * Acceptable properties for each column configuration object are:
171 * <div class="mdetail-params"><ul>
172 * <li><b><tt>align</tt></b> : String<div class="sub-desc">Set the CSS text-align property
173 * of the column. Defaults to <tt>'left'</tt>.</div></li>
174 * <li><b><tt>dataIndex</tt></b> : String<div class="sub-desc">See {@link Ext.grid.Column}.
175 * {@link Ext.grid.Column#dataIndex dataIndex} for details.</div></li>
176 * <li><b><tt>header</tt></b> : String<div class="sub-desc">See {@link Ext.grid.Column}.
177 * {@link Ext.grid.Column#header header} for details.</div></li>
178 * <li><b><tt>tpl</tt></b> : String<div class="sub-desc">Specify a string to pass as the
179 * configuration string for {@link Ext.XTemplate}. By default an {@link Ext.XTemplate}
180 * will be implicitly created using the <tt>dataIndex</tt>.</div></li>
181 * <li><b><tt>width</tt></b> : Number<div class="sub-desc">Percentage of the container width
182 * this column should be allocated. Columns that have no width specified will be
183 * allocated with an equal percentage to fill 100% of the container width. To easily take
184 * advantage of the full container width, leave the width of at least one column undefined.
185 * Note that if you do not want to take up the full width of the container, the width of
186 * every column needs to be explicitly defined.</div></li>
189 <div id="cfg-Ext.list.ListView-columnSort"></div>/**
190 * @cfg {Boolean/Object} columnSort
191 * Specify <tt>true</tt> or specify a configuration object for {@link Ext.list.ListView.Sorter}
192 * to enable the columns to be sortable (defaults to <tt>true</tt>).
195 <div id="cfg-Ext.list.ListView-internalTpl"></div>/**
196 * @cfg {String/Array} internalTpl
197 * The template to be used for the header row. See {@link #tpl} for more details.
201 * IE has issues when setting percentage based widths to 100%. Default to 99.
203 maxColumnWidth: Ext.isIE ? 99 : 100,
205 initComponent : function(){
206 if(this.columnResize){
207 this.colResizer = new Ext.list.ColumnResizer(this.colResizer);
208 this.colResizer.init(this);
211 this.colSorter = new Ext.list.Sorter(this.columnSort);
212 this.colSorter.init(this);
214 if(!this.internalTpl){
215 this.internalTpl = new Ext.XTemplate(
216 '<div class="x-list-header"><div class="x-list-header-inner">',
217 '<tpl for="columns">',
218 '<div style="width:{[values.width*100]}%;text-align:{align};"><em unselectable="on" id="',this.id, '-xlhd-{#}">',
222 '<div class="x-clear"></div>',
224 '<div class="x-list-body"><div class="x-list-body-inner">',
229 this.tpl = new Ext.XTemplate(
232 '<tpl for="parent.columns">',
233 '<dt style="width:{[values.width*100]}%;text-align:{align};">',
234 '<em unselectable="on"<tpl if="cls"> class="{cls}</tpl>">',
235 '{[values.tpl.apply(parent)]}',
238 '<div class="x-clear"></div>',
244 var cs = this.columns,
250 for(var i = 0; i < len; i++){
253 c.xtype = c.xtype ? (/^lv/.test(c.xtype) ? c.xtype : 'lv' + c.xtype) : 'lvcolumn';
257 allocatedWidth += c.width*100;
258 if(allocatedWidth > this.maxColumnWidth){
259 c.width -= (allocatedWidth - this.maxColumnWidth) / 100;
266 cs = this.columns = columns;
268 // auto calculate missing column widths
269 if(colsWithWidth < len){
270 var remaining = len - colsWithWidth;
271 if(allocatedWidth < this.maxColumnWidth){
272 var perCol = ((this.maxColumnWidth-allocatedWidth) / remaining)/100;
273 for(var j = 0; j < len; j++){
281 Ext.list.ListView.superclass.initComponent.call(this);
284 onRender : function(){
288 Ext.list.ListView.superclass.onRender.apply(this, arguments);
290 this.internalTpl.overwrite(this.el, {columns: this.columns});
292 this.innerBody = Ext.get(this.el.dom.childNodes[1].firstChild);
293 this.innerHd = Ext.get(this.el.dom.firstChild.firstChild);
295 if(this.hideHeaders){
296 this.el.dom.firstChild.style.display = 'none';
300 getTemplateTarget : function(){
301 return this.innerBody;
304 <div id="method-Ext.list.ListView-collectData"></div>/**
305 * <p>Function which can be overridden which returns the data object passed to this
306 * view's {@link #tpl template} to render the whole ListView. The returned object
307 * shall contain the following properties:</p>
308 * <div class="mdetail-params"><ul>
309 * <li><b>columns</b> : String<div class="sub-desc">See <tt>{@link #columns}</tt></div></li>
310 * <li><b>rows</b> : String<div class="sub-desc">See
311 * <tt>{@link Ext.DataView}.{@link Ext.DataView#collectData collectData}</div></li>
313 * @param {Array} records An Array of {@link Ext.data.Record}s to be rendered into the DataView.
314 * @param {Number} startIndex the index number of the Record being prepared for rendering.
315 * @return {Object} A data object containing properties to be processed by a repeating
316 * XTemplate as described above.
318 collectData : function(){
319 var rs = Ext.list.ListView.superclass.collectData.apply(this, arguments);
321 columns: this.columns,
326 verifyInternalSize : function(){
328 this.onResize(this.lastSize.width, this.lastSize.height);
333 onResize : function(w, h){
334 var body = this.innerBody.dom,
335 header = this.innerHd.dom,
336 scrollWidth = w - Ext.num(this.scrollOffset, Ext.getScrollBarWidth()) + 'px',
342 parentNode = body.parentNode;
344 if(this.reserveScrollOffset || ((parentNode.offsetWidth - parentNode.clientWidth) > 10)){
345 body.style.width = scrollWidth;
346 header.style.width = scrollWidth;
348 body.style.width = w + 'px';
349 header.style.width = w + 'px';
350 setTimeout(function(){
351 if((parentNode.offsetWidth - parentNode.clientWidth) > 10){
352 body.style.width = scrollWidth;
353 header.style.width = scrollWidth;
359 parentNode.style.height = Math.max(0, h - header.parentNode.offsetHeight) + 'px';
363 updateIndexes : function(){
364 Ext.list.ListView.superclass.updateIndexes.apply(this, arguments);
365 this.verifyInternalSize();
368 findHeaderIndex : function(header){
369 header = header.dom || header;
370 var parentNode = header.parentNode,
371 children = parentNode.parentNode.childNodes,
374 for(; c = children[i]; i++){
382 setHdWidths : function(){
383 var els = this.innerHd.dom.getElementsByTagName('div'),
385 columns = this.columns,
386 len = columns.length;
389 els[i].style.width = (columns[i].width*100) + '%';
394 Ext.reg('listview', Ext.list.ListView);
396 // Backwards compatibility alias
397 Ext.ListView = Ext.list.ListView;</pre>