Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / src / grid / feature / RowBody.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.feature.RowBody
17  * @extends Ext.grid.feature.Feature
18  *
19  * The rowbody feature enhances the grid's markup to have an additional
20  * tr -> td -> div which spans the entire width of the original row.
21  *
22  * This is useful to to associate additional information with a particular
23  * record in a grid.
24  *
25  * Rowbodies are initially hidden unless you override getAdditionalData.
26  *
27  * Will expose additional events on the gridview with the prefix of 'rowbody'.
28  * For example: 'rowbodyclick', 'rowbodydblclick', 'rowbodycontextmenu'.
29  *
30  * @ftype rowbody
31  */
32 Ext.define('Ext.grid.feature.RowBody', {
33     extend: 'Ext.grid.feature.Feature',
34     alias: 'feature.rowbody',
35     rowBodyHiddenCls: Ext.baseCSSPrefix + 'grid-row-body-hidden',
36     rowBodyTrCls: Ext.baseCSSPrefix + 'grid-rowbody-tr',
37     rowBodyTdCls: Ext.baseCSSPrefix + 'grid-cell-rowbody',
38     rowBodyDivCls: Ext.baseCSSPrefix + 'grid-rowbody',
39
40     eventPrefix: 'rowbody',
41     eventSelector: '.' + Ext.baseCSSPrefix + 'grid-rowbody-tr',
42     
43     getRowBody: function(values) {
44         return [
45             '<tr class="' + this.rowBodyTrCls + ' {rowBodyCls}">',
46                 '<td class="' + this.rowBodyTdCls + '" colspan="{rowBodyColspan}">',
47                     '<div class="' + this.rowBodyDivCls + '">{rowBody}</div>',
48                 '</td>',
49             '</tr>'
50         ].join('');
51     },
52     
53     // injects getRowBody into the metaRowTpl.
54     getMetaRowTplFragments: function() {
55         return {
56             getRowBody: this.getRowBody,
57             rowBodyTrCls: this.rowBodyTrCls,
58             rowBodyTdCls: this.rowBodyTdCls,
59             rowBodyDivCls: this.rowBodyDivCls
60         };
61     },
62
63     mutateMetaRowTpl: function(metaRowTpl) {
64         metaRowTpl.push('{[this.getRowBody(values)]}');
65     },
66
67     /**
68      * Provide additional data to the prepareData call within the grid view.
69      * The rowbody feature adds 3 additional variables into the grid view's template.
70      * These are rowBodyCls, rowBodyColspan, and rowBody.
71      * @param {Object} data The data for this particular record.
72      * @param {Number} idx The row index for this record.
73      * @param {Ext.data.Model} record The record instance
74      * @param {Object} orig The original result from the prepareData call to massage.
75      */
76     getAdditionalData: function(data, idx, record, orig) {
77         var headerCt = this.view.headerCt,
78             colspan  = headerCt.getColumnCount();
79
80         return {
81             rowBody: "",
82             rowBodyCls: this.rowBodyCls,
83             rowBodyColspan: colspan
84         };
85     }
86 });