Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / src / grid / feature / Feature.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.Feature
17  * @extends Ext.util.Observable
18  * 
19  * A feature is a type of plugin that is specific to the {@link Ext.grid.Panel}. It provides several
20  * hooks that allows the developer to inject additional functionality at certain points throughout the 
21  * grid creation cycle. This class provides the base template methods that are available to the developer,
22  * it should be extended.
23  * 
24  * There are several built in features that extend this class, for example:
25  *
26  *  - {@link Ext.grid.feature.Grouping} - Shows grid rows in groups as specified by the {@link Ext.data.Store}
27  *  - {@link Ext.grid.feature.RowBody} - Adds a body section for each grid row that can contain markup.
28  *  - {@link Ext.grid.feature.Summary} - Adds a summary row at the bottom of the grid with aggregate totals for a column.
29  * 
30  * ## Using Features
31  * A feature is added to the grid by specifying it an array of features in the configuration:
32  * 
33  *     var groupingFeature = Ext.create('Ext.grid.feature.Grouping');
34  *     Ext.create('Ext.grid.Panel', {
35  *         // other options
36  *         features: [groupingFeature]
37  *     });
38  * 
39  * @abstract
40  */
41 Ext.define('Ext.grid.feature.Feature', {
42     extend: 'Ext.util.Observable',
43     alias: 'feature.feature',
44     
45     isFeature: true,
46     disabled: false,
47     
48     /**
49      * @property {Boolean}
50      * Most features will expose additional events, some may not and will
51      * need to change this to false.
52      */
53     hasFeatureEvent: true,
54     
55     /**
56      * @property {String}
57      * Prefix to use when firing events on the view.
58      * For example a prefix of group would expose "groupclick", "groupcontextmenu", "groupdblclick".
59      */
60     eventPrefix: null,
61     
62     /**
63      * @property {String}
64      * Selector used to determine when to fire the event with the eventPrefix.
65      */
66     eventSelector: null,
67     
68     /**
69      * @property {Ext.view.Table}
70      * Reference to the TableView.
71      */
72     view: null,
73     
74     /**
75      * @property {Ext.grid.Panel}
76      * Reference to the grid panel
77      */
78     grid: null,
79     
80     /**
81      * Most features will not modify the data returned to the view.
82      * This is limited to one feature that manipulates the data per grid view.
83      */
84     collectData: false,
85         
86     getFeatureTpl: function() {
87         return '';
88     },
89     
90     /**
91      * Abstract method to be overriden when a feature should add additional
92      * arguments to its event signature. By default the event will fire:
93      * - view - The underlying Ext.view.Table
94      * - featureTarget - The matched element by the defined {@link #eventSelector}
95      *
96      * The method must also return the eventName as the first index of the array
97      * to be passed to fireEvent.
98      */
99     getFireEventArgs: function(eventName, view, featureTarget, e) {
100         return [eventName, view, featureTarget, e];
101     },
102     
103     /**
104      * Approriate place to attach events to the view, selectionmodel, headerCt, etc
105      */
106     attachEvents: function() {
107         
108     },
109     
110     getFragmentTpl: function() {
111         return;
112     },
113     
114     /**
115      * Allows a feature to mutate the metaRowTpl.
116      * The array received as a single argument can be manipulated to add things
117      * on the end/begining of a particular row.
118      */
119     mutateMetaRowTpl: function(metaRowTplArray) {
120         
121     },
122     
123     /**
124      * Allows a feature to inject member methods into the metaRowTpl. This is
125      * important for embedding functionality which will become part of the proper
126      * row tpl.
127      */
128     getMetaRowTplFragments: function() {
129         return {};
130     },
131
132     getTableFragments: function() {
133         return {};
134     },
135     
136     /**
137      * Provide additional data to the prepareData call within the grid view.
138      * @param {Object} data The data for this particular record.
139      * @param {Number} idx The row index for this record.
140      * @param {Ext.data.Model} record The record instance
141      * @param {Object} orig The original result from the prepareData call to massage.
142      */
143     getAdditionalData: function(data, idx, record, orig) {
144         return {};
145     },
146     
147     /**
148      * Enable a feature
149      */
150     enable: function() {
151         this.disabled = false;
152     },
153     
154     /**
155      * Disable a feature
156      */
157     disable: function() {
158         this.disabled = true;
159     }
160     
161 });