Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / src / grid / RowNumberer.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 /**
16  * This is a utility class that can be passed into a {@link Ext.grid.column.Column} as a column config that provides
17  * an automatic row numbering column.
18  * 
19  * Usage:
20  *
21  *     columns: [
22  *         {xtype: 'rownumberer'},
23  *         {text: "Company", flex: 1, sortable: true, dataIndex: 'company'},
24  *         {text: "Price", width: 120, sortable: true, renderer: Ext.util.Format.usMoney, dataIndex: 'price'},
25  *         {text: "Change", width: 120, sortable: true, dataIndex: 'change'},
26  *         {text: "% Change", width: 120, sortable: true, dataIndex: 'pctChange'},
27  *         {text: "Last Updated", width: 120, sortable: true, renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}
28  *     ]
29  *
30  */
31 Ext.define('Ext.grid.RowNumberer', {
32     extend: 'Ext.grid.column.Column',
33     alias: 'widget.rownumberer',
34
35     /**
36      * @cfg {String} text
37      * Any valid text or HTML fragment to display in the header cell for the row number column.
38      */
39     text: "&#160",
40
41     /**
42      * @cfg {Number} width
43      * The default width in pixels of the row number column.
44      */
45     width: 23,
46
47     /**
48      * @cfg {Boolean} sortable
49      * True if the row number column is sortable.
50      * @hide
51      */
52     sortable: false,
53
54     align: 'right',
55
56     constructor : function(config){
57         this.callParent(arguments);
58         if (this.rowspan) {
59             this.renderer = Ext.Function.bind(this.renderer, this);
60         }
61     },
62
63     // private
64     resizable: false,
65     hideable: false,
66     menuDisabled: true,
67     dataIndex: '',
68     cls: Ext.baseCSSPrefix + 'row-numberer',
69     rowspan: undefined,
70
71     // private
72     renderer: function(value, metaData, record, rowIdx, colIdx, store) {
73         if (this.rowspan){
74             metaData.cellAttr = 'rowspan="'+this.rowspan+'"';
75         }
76
77         metaData.tdCls = Ext.baseCSSPrefix + 'grid-cell-special';
78         return store.indexOfTotal(record) + 1;
79     }
80 });
81