3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js"><div id="cls-Ext.list.ListView"></div>/**
\r
10 * @class Ext.list.ListView
\r
11 * @extends Ext.DataView
\r
12 * <p>Ext.list.ListView is a fast and light-weight implentation of a
\r
13 * {@link Ext.grid.GridPanel Grid} like view with the following characteristics:</p>
\r
14 * <div class="mdetail-params"><ul>
\r
15 * <li>resizable columns</li>
\r
16 * <li>selectable</li>
\r
17 * <li>column widths are initially proportioned by percentage based on the container
\r
18 * width and number of columns</li>
\r
19 * <li>uses templates to render the data in any required format</li>
\r
20 * <li>no horizontal scrolling</li>
\r
21 * <li>no editing</li>
\r
23 * <p>Example usage:</p>
\r
25 // consume JSON of this form:
\r
29 "name":"dance_fever.jpg",
\r
31 "lastmod":1236974993000,
\r
32 "url":"images\/thumbs\/dance_fever.jpg"
\r
35 "name":"zack_sink.jpg",
\r
37 "lastmod":1236974993000,
\r
38 "url":"images\/thumbs\/zack_sink.jpg"
\r
42 var store = new Ext.data.JsonStore({
\r
43 url: 'get-images.php',
\r
47 {name:'size', type: 'float'},
\r
48 {name:'lastmod', type:'date', dateFormat:'timestamp'}
\r
53 var listView = new Ext.list.ListView({
\r
56 emptyText: 'No images to display',
\r
57 reserveScrollOffset: true,
\r
63 header: 'Last Modified',
\r
65 dataIndex: 'lastmod',
\r
66 tpl: '{lastmod:date("m-d h:i a")}'
\r
70 tpl: '{size:fileSize}', // format using Ext.util.Format.fileSize()
\r
75 // put it in a Panel so it looks pretty
\r
76 var panel = new Ext.Panel({
\r
82 title:'Simple ListView <i>(0 items selected)</i>',
\r
85 panel.render(document.body);
\r
87 // little bit of feedback
\r
88 listView.on('selectionchange', function(view, nodes){
\r
89 var l = nodes.length;
\r
90 var s = l != 1 ? 's' : '';
\r
91 panel.setTitle('Simple ListView <i>('+l+' item'+s+' selected)</i>');
\r
95 * @param {Object} config
\r
98 Ext.list.ListView = Ext.extend(Ext.DataView, {
\r
99 <div id="prop-Ext.list.ListView-disableHeaders"></div>/**
\r
100 * Set this property to <tt>true</tt> to disable the header click handler disabling sort
\r
101 * (defaults to <tt>false</tt>).
\r
103 * @property disableHeaders
\r
105 <div id="cfg-Ext.list.ListView-hideHeaders"></div>/**
\r
106 * @cfg {Boolean} hideHeaders
\r
107 * <tt>true</tt> to hide the {@link #internalTpl header row} (defaults to <tt>false</tt> so
\r
108 * the {@link #internalTpl header row} will be shown).
\r
110 <div id="cfg-Ext.list.ListView-itemSelector"></div>/**
\r
111 * @cfg {String} itemSelector
\r
112 * Defaults to <tt>'dl'</tt> to work with the preconfigured <b><tt>{@link Ext.DataView#tpl tpl}</tt></b>.
\r
113 * This setting specifies the CSS selector (e.g. <tt>div.some-class</tt> or <tt>span:first-child</tt>)
\r
114 * that will be used to determine what nodes the ListView will be working with.
\r
116 itemSelector: 'dl',
\r
117 <div id="cfg-Ext.list.ListView-selectedClass"></div>/**
\r
118 * @cfg {String} selectedClass The CSS class applied to a selected row (defaults to
\r
119 * <tt>'x-list-selected'</tt>). An example overriding the default styling:
\r
121 .x-list-selected {background-color: yellow;}
\r
125 selectedClass:'x-list-selected',
\r
126 <div id="cfg-Ext.list.ListView-overClass"></div>/**
\r
127 * @cfg {String} overClass The CSS class applied when over a row (defaults to
\r
128 * <tt>'x-list-over'</tt>). An example overriding the default styling:
\r
130 .x-list-over {background-color: orange;}
\r
134 overClass:'x-list-over',
\r
135 <div id="cfg-Ext.list.ListView-reserveScrollOffset"></div>/**
\r
136 * @cfg {Boolean} reserveScrollOffset
\r
137 * By default will defer accounting for the configured <b><tt>{@link #scrollOffset}</tt></b>
\r
138 * for 10 milliseconds. Specify <tt>true</tt> to account for the configured
\r
139 * <b><tt>{@link #scrollOffset}</tt></b> immediately.
\r
141 <div id="cfg-Ext.list.ListView-scrollOffset"></div>/**
\r
142 * @cfg {Number} scrollOffset The amount of space to reserve for the scrollbar (defaults to
\r
143 * <tt>undefined</tt>). If an explicit value isn't specified, this will be automatically
\r
146 scrollOffset : undefined,
\r
147 <div id="cfg-Ext.list.ListView-columnResize"></div>/**
\r
148 * @cfg {Boolean/Object} columnResize
\r
149 * Specify <tt>true</tt> or specify a configuration object for {@link Ext.list.ListView.ColumnResizer}
\r
150 * to enable the columns to be resizable (defaults to <tt>true</tt>).
\r
152 columnResize: true,
\r
153 <div id="cfg-Ext.list.ListView-columns"></div>/**
\r
154 * @cfg {Array} columns An array of column configuration objects, for example:
\r
160 tpl: '{size:fileSize}',
\r
164 * Acceptable properties for each column configuration object are:
\r
165 * <div class="mdetail-params"><ul>
\r
166 * <li><b><tt>align</tt></b> : String<div class="sub-desc">Set the CSS text-align property
\r
167 * of the column. Defaults to <tt>'left'</tt>.</div></li>
\r
168 * <li><b><tt>dataIndex</tt></b> : String<div class="sub-desc">See {@link Ext.grid.Column}.
\r
169 * {@link Ext.grid.Column#dataIndex dataIndex} for details.</div></li>
\r
170 * <li><b><tt>header</tt></b> : String<div class="sub-desc">See {@link Ext.grid.Column}.
\r
171 * {@link Ext.grid.Column#header header} for details.</div></li>
\r
172 * <li><b><tt>tpl</tt></b> : String<div class="sub-desc">Specify a string to pass as the
\r
173 * configuration string for {@link Ext.XTemplate}. By default an {@link Ext.XTemplate}
\r
174 * will be implicitly created using the <tt>dataIndex</tt>.</div></li>
\r
175 * <li><b><tt>width</tt></b> : Number<div class="sub-desc">Percentage of the container width
\r
176 * this column should be allocated. Columns that have no width specified will be
\r
177 * allocated with an equal percentage to fill 100% of the container width. To easily take
\r
178 * advantage of the full container width, leave the width of at least one column undefined.
\r
179 * Note that if you do not want to take up the full width of the container, the width of
\r
180 * every column needs to be explicitly defined.</div></li>
\r
183 <div id="cfg-Ext.list.ListView-columnSort"></div>/**
\r
184 * @cfg {Boolean/Object} columnSort
\r
185 * Specify <tt>true</tt> or specify a configuration object for {@link Ext.list.ListView.Sorter}
\r
186 * to enable the columns to be sortable (defaults to <tt>true</tt>).
\r
189 <div id="cfg-Ext.list.ListView-internalTpl"></div>/**
\r
190 * @cfg {String/Array} internalTpl
\r
191 * The template to be used for the header row. See {@link #tpl} for more details.
\r
195 * IE has issues when setting percentage based widths to 100%. Default to 99.
\r
197 maxWidth: Ext.isIE ? 99 : 100,
\r
199 initComponent : function(){
\r
200 if(this.columnResize){
\r
201 this.colResizer = new Ext.list.ColumnResizer(this.colResizer);
\r
202 this.colResizer.init(this);
\r
204 if(this.columnSort){
\r
205 this.colSorter = new Ext.list.Sorter(this.columnSort);
\r
206 this.colSorter.init(this);
\r
208 if(!this.internalTpl){
\r
209 this.internalTpl = new Ext.XTemplate(
\r
210 '<div class="x-list-header"><div class="x-list-header-inner">',
\r
211 '<tpl for="columns">',
\r
212 '<div style="width:{[values.width*100]}%;text-align:{align};"><em unselectable="on" id="',this.id, '-xlhd-{#}">',
\r
216 '<div class="x-clear"></div>',
\r
218 '<div class="x-list-body"><div class="x-list-body-inner">',
\r
223 this.tpl = new Ext.XTemplate(
\r
224 '<tpl for="rows">',
\r
226 '<tpl for="parent.columns">',
\r
227 '<dt style="width:{[values.width*100]}%;text-align:{align};">',
\r
228 '<em unselectable="on"<tpl if="cls"> class="{cls}</tpl>">',
\r
229 '{[values.tpl.apply(parent)]}',
\r
232 '<div class="x-clear"></div>',
\r
238 var cs = this.columns,
\r
239 allocatedWidth = 0,
\r
240 colsWithWidth = 0,
\r
244 for(var i = 0; i < len; i++){
\r
247 c.xtype = c.xtype ? (/^lv/.test(c.xtype) ? c.xtype : 'lv' + c.xtype) : 'lvcolumn';
\r
251 allocatedWidth += c.width*100;
\r
257 cs = this.columns = columns;
\r
259 // auto calculate missing column widths
\r
260 if(colsWithWidth < len){
\r
261 var remaining = len - colsWithWidth;
\r
262 if(allocatedWidth < this.maxWidth){
\r
263 var perCol = ((this.maxWidth-allocatedWidth) / remaining)/100;
\r
264 for(var j = 0; j < len; j++){
\r
272 Ext.list.ListView.superclass.initComponent.call(this);
\r
275 onRender : function(){
\r
277 cls: 'x-list-wrap'
\r
279 Ext.list.ListView.superclass.onRender.apply(this, arguments);
\r
281 this.internalTpl.overwrite(this.el, {columns: this.columns});
\r
283 this.innerBody = Ext.get(this.el.dom.childNodes[1].firstChild);
\r
284 this.innerHd = Ext.get(this.el.dom.firstChild.firstChild);
\r
286 if(this.hideHeaders){
\r
287 this.el.dom.firstChild.style.display = 'none';
\r
291 getTemplateTarget : function(){
\r
292 return this.innerBody;
\r
295 <div id="method-Ext.list.ListView-collectData"></div>/**
\r
296 * <p>Function which can be overridden which returns the data object passed to this
\r
297 * view's {@link #tpl template} to render the whole ListView. The returned object
\r
298 * shall contain the following properties:</p>
\r
299 * <div class="mdetail-params"><ul>
\r
300 * <li><b>columns</b> : String<div class="sub-desc">See <tt>{@link #columns}</tt></div></li>
\r
301 * <li><b>rows</b> : String<div class="sub-desc">See
\r
302 * <tt>{@link Ext.DataView}.{@link Ext.DataView#collectData collectData}</div></li>
\r
304 * @param {Array} records An Array of {@link Ext.data.Record}s to be rendered into the DataView.
\r
305 * @param {Number} startIndex the index number of the Record being prepared for rendering.
\r
306 * @return {Object} A data object containing properties to be processed by a repeating
\r
307 * XTemplate as described above.
\r
309 collectData : function(){
\r
310 var rs = Ext.list.ListView.superclass.collectData.apply(this, arguments);
\r
312 columns: this.columns,
\r
317 verifyInternalSize : function(){
\r
319 this.onResize(this.lastSize.width, this.lastSize.height);
\r
324 onResize : function(w, h){
\r
325 var bd = this.innerBody.dom;
\r
326 var hd = this.innerHd.dom
\r
330 var bdp = bd.parentNode;
\r
331 if(Ext.isNumber(w)){
\r
332 var sw = w - Ext.num(this.scrollOffset, Ext.getScrollBarWidth());
\r
333 if(this.reserveScrollOffset || ((bdp.offsetWidth - bdp.clientWidth) > 10)){
\r
334 bd.style.width = sw + 'px';
\r
335 hd.style.width = sw + 'px';
\r
337 bd.style.width = w + 'px';
\r
338 hd.style.width = w + 'px';
\r
339 setTimeout(function(){
\r
340 if((bdp.offsetWidth - bdp.clientWidth) > 10){
\r
341 bd.style.width = sw + 'px';
\r
342 hd.style.width = sw + 'px';
\r
347 if(Ext.isNumber(h)){
\r
348 bdp.style.height = (h - hd.parentNode.offsetHeight) + 'px';
\r
352 updateIndexes : function(){
\r
353 Ext.list.ListView.superclass.updateIndexes.apply(this, arguments);
\r
354 this.verifyInternalSize();
\r
357 findHeaderIndex : function(hd){
\r
359 var pn = hd.parentNode, cs = pn.parentNode.childNodes;
\r
360 for(var i = 0, c; c = cs[i]; i++){
\r
368 setHdWidths : function(){
\r
369 var els = this.innerHd.dom.getElementsByTagName('div');
\r
370 for(var i = 0, cs = this.columns, len = cs.length; i < len; i++){
\r
371 els[i].style.width = (cs[i].width*100) + '%';
\r
376 Ext.reg('listview', Ext.list.ListView);
\r
378 // Backwards compatibility alias
\r
379 Ext.ListView = Ext.list.ListView;</pre>
\r