Upgrade to ExtJS 4.0.2 - Released 06/09/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  * @class Ext.grid.RowNumberer
17  * @extends Ext.grid.column.Column
18  * This is a utility class that can be passed into a {@link Ext.grid.column.Column} as a column config that provides
19  * an automatic row numbering column.
20  * <br>Usage:<br><pre><code>
21 columns: [
22     Ext.create('Ext.grid.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  *</code></pre>
30  */
31 Ext.define('Ext.grid.RowNumberer', {
32     extend: 'Ext.grid.column.Column',
33     alias: 'widget.rownumberer',
34     /**
35      * @cfg {String} text Any valid text or HTML fragment to display in the header cell for the row
36      * number column (defaults to '&#160').
37      */
38     text: "&#160",
39
40     /**
41      * @cfg {Number} width The default width in pixels of the row number column (defaults to 23).
42      */
43     width: 23,
44
45     /**
46      * @cfg {Boolean} sortable True if the row number column is sortable (defaults to false).
47      * @hide
48      */
49     sortable: false,
50
51     align: 'right',
52
53     constructor : function(config){
54         this.callParent(arguments);
55         if (this.rowspan) {
56             this.renderer = Ext.Function.bind(this.renderer, this);
57         }
58     },
59
60     // private
61     fixed: true,
62     hideable: false,
63     menuDisabled: true,
64     dataIndex: '',
65     cls: Ext.baseCSSPrefix + 'row-numberer',
66     rowspan: undefined,
67
68     // private
69     renderer: function(value, metaData, record, rowIdx, colIdx, store) {
70         if (this.rowspan){
71             metaData.cellAttr = 'rowspan="'+this.rowspan+'"';
72         }
73
74         metaData.tdCls = Ext.baseCSSPrefix + 'grid-cell-special';
75         return store.indexOfTotal(record) + 1;
76     }
77 });
78