Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / src / grid / RowNumberer.js
1 /**
2  * @class Ext.grid.RowNumberer
3  * @extends Ext.grid.column.Column
4  * This is a utility class that can be passed into a {@link Ext.grid.column.Column} as a column config that provides
5  * an automatic row numbering column.
6  * <br>Usage:<br><pre><code>
7 columns: [
8     Ext.create('Ext.grid.RowNumberer'),
9     {text: "Company", flex: 1, sortable: true, dataIndex: 'company'},
10     {text: "Price", width: 120, sortable: true, renderer: Ext.util.Format.usMoney, dataIndex: 'price'},
11     {text: "Change", width: 120, sortable: true, dataIndex: 'change'},
12     {text: "% Change", width: 120, sortable: true, dataIndex: 'pctChange'},
13     {text: "Last Updated", width: 120, sortable: true, renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}
14 ]
15  *</code></pre>
16  * @constructor
17  * @param {Object} config The configuration options
18  */
19 Ext.define('Ext.grid.RowNumberer', {
20     extend: 'Ext.grid.column.Column',
21     alias: 'widget.rownumberer',
22     /**
23      * @cfg {String} text Any valid text or HTML fragment to display in the header cell for the row
24      * number column (defaults to '&#160').
25      */
26     text: "&#160",
27
28     /**
29      * @cfg {Number} width The default width in pixels of the row number column (defaults to 23).
30      */
31     width: 23,
32
33     /**
34      * @cfg {Boolean} sortable True if the row number column is sortable (defaults to false).
35      * @hide
36      */
37     sortable: false,
38
39     align: 'right',
40
41     constructor : function(config){
42         this.callParent(arguments);
43         if (this.rowspan) {
44             this.renderer = Ext.Function.bind(this.renderer, this);
45         }
46     },
47
48     // private
49     fixed: true,
50     hideable: false,
51     menuDisabled: true,
52     dataIndex: '',
53     cls: Ext.baseCSSPrefix + 'row-numberer',
54     rowspan: undefined,
55
56     // private
57     renderer: function(value, metaData, record, rowIdx, colIdx, store) {
58         if (this.rowspan){
59             metaData.cellAttr = 'rowspan="'+this.rowspan+'"';
60         }
61
62         metaData.tdCls = Ext.baseCSSPrefix + 'grid-cell-special';
63         return store.indexOfTotal(record) + 1;
64     }
65 });