3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
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.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @author Aaron Conran
17 * @class Ext.grid.Panel
18 * @extends Ext.panel.Table
20 * Grids are an excellent way of showing large amounts of tabular data on the client side. Essentially a supercharged
21 * `<table>`, GridPanel makes it easy to fetch, sort and filter large amounts of data.
23 * Grids are composed of 2 main pieces - a {@link Ext.data.Store Store} full of data and a set of columns to render.
25 * {@img Ext.grid.Panel/Ext.grid.Panel1.png Ext.grid.Panel component}
29 * Ext.create('Ext.data.Store', {
30 * storeId:'simpsonsStore',
31 * fields:['name', 'email', 'phone'],
33 * {"name":"Lisa", "email":"lisa@simpsons.com", "phone":"555-111-1224"},
34 * {"name":"Bart", "email":"bart@simpsons.com", "phone":"555--222-1234"},
35 * {"name":"Homer", "email":"home@simpsons.com", "phone":"555-222-1244"},
36 * {"name":"Marge", "email":"marge@simpsons.com", "phone":"555-222-1254"}
47 * Ext.create('Ext.grid.Panel', {
49 * store: Ext.data.StoreManager.lookup('simpsonsStore'),
51 * {header: 'Name', dataIndex: 'name'},
52 * {header: 'Email', dataIndex: 'email', flex:1},
53 * {header: 'Phone', dataIndex: 'phone'}
57 * renderTo: Ext.getBody()
60 * The code above produces a simple grid with three columns. We specified a Store which will load JSON data inline.
61 * In most apps we would be placing the grid inside another container and wouldn't need to use the
62 * {@link #height}, {@link #width} and {@link #renderTo} configurations but they are included here to make it easy to get
65 * The grid we created above will contain a header bar with a title ('Simpsons'), a row of column headers directly underneath
66 * and finally the grid rows under the headers.
68 * ## Configuring columns
70 * By default, each column is sortable and will toggle between ASC and DESC sorting when you click on its header. Each
71 * column header is also reorderable by default, and each gains a drop-down menu with options to hide and show columns.
72 * It's easy to configure each column - here we use the same example as above and just modify the columns config:
94 * We turned off sorting and hiding on the 'Name' column so clicking its header now has no effect. We also made the Email
95 * column hidden by default (it can be shown again by using the menu on any other column). We also set the Phone column to
96 * a fixed with of 100px and flexed the Name column, which means it takes up all remaining width after the other columns
97 * have been accounted for. See the {@link Ext.grid.column.Column column docs} for more details.
101 * As well as customizing columns, it's easy to alter the rendering of individual cells using renderers. A renderer is
102 * tied to a particular column and is passed the value that would be rendered into each cell in that column. For example,
103 * we could define a renderer function for the email column to turn each email address into a mailto link:
108 * dataIndex: 'email',
109 * renderer: function(value) {
110 * return Ext.String.format('<a href="mailto:{0}">{1}</a>', value, value);
115 * See the {@link Ext.grid.column.Column column docs} for more information on renderers.
117 * ## Selection Models
119 * Sometimes all you want is to render data onto the screen for viewing, but usually it's necessary to interact with or
120 * update that data. Grids use a concept called a Selection Model, which is simply a mechanism for selecting some part of
121 * the data in the grid. The two main types of Selection Model are RowSelectionModel, where entire rows are selected, and
122 * CellSelectionModel, where individual cells are selected.
124 * Grids use a Row Selection Model by default, but this is easy to customise like so:
126 * Ext.create('Ext.grid.Panel', {
127 * selType: 'cellmodel',
131 * Specifying the `cellmodel` changes a couple of things. Firstly, clicking on a cell now
132 * selects just that cell (using a {@link Ext.selection.RowModel rowmodel} will select the entire row), and secondly the
133 * keyboard navigation will walk from cell to cell instead of row to row. Cell-based selection models are usually used in
134 * conjunction with editing.
136 * {@img Ext.grid.Panel/Ext.grid.Panel2.png Ext.grid.Panel cell editing}
140 * Grid has built-in support for in-line editing. There are two chief editing modes - cell editing and row editing. Cell
141 * editing is easy to add to your existing column setup - here we'll just modify the example above to include an editor
142 * on both the name and the email columns:
144 * Ext.create('Ext.grid.Panel', {
146 * store: Ext.data.StoreManager.lookup('simpsonsStore'),
148 * {header: 'Name', dataIndex: 'name', field: 'textfield'},
149 * {header: 'Email', dataIndex: 'email', flex:1,
155 * {header: 'Phone', dataIndex: 'phone'}
157 * selType: 'cellmodel',
159 * Ext.create('Ext.grid.plugin.CellEditing', {
165 * renderTo: Ext.getBody()
168 * This requires a little explanation. We're passing in {@link #store store} and {@link #columns columns} as normal, but
169 * this time we've also specified a {@link #field field} on two of our columns. For the Name column we just want a default
170 * textfield to edit the value, so we specify 'textfield'. For the Email column we customized the editor slightly by
171 * passing allowBlank: false, which will provide inline validation.
173 * To support cell editing, we also specified that the grid should use the 'cellmodel' {@link #selType}, and created an
174 * instance of the {@link Ext.grid.plugin.CellEditing CellEditing plugin}, which we configured to activate each editor after a
177 * {@img Ext.grid.Panel/Ext.grid.Panel3.png Ext.grid.Panel row editing}
181 * The other type of editing is row-based editing, using the RowEditor component. This enables you to edit an entire row
182 * at a time, rather than editing cell by cell. Row Editing works in exactly the same way as cell editing, all we need to
183 * do is change the plugin type to {@link Ext.grid.plugin.RowEditing}, and set the selType to 'rowmodel':
185 * Ext.create('Ext.grid.Panel', {
187 * store: Ext.data.StoreManager.lookup('simpsonsStore'),
189 * {header: 'Name', dataIndex: 'name', field: 'textfield'},
190 * {header: 'Email', dataIndex: 'email', flex:1,
196 * {header: 'Phone', dataIndex: 'phone'}
198 * selType: 'rowmodel',
200 * Ext.create('Ext.grid.plugin.RowEditing', {
206 * renderTo: Ext.getBody()
209 * Again we passed some configuration to our {@link Ext.grid.plugin.RowEditing} plugin, and now when we click each row a row
210 * editor will appear and enable us to edit each of the columns we have specified an editor for.
212 * ## Sorting & Filtering
214 * Every grid is attached to a {@link Ext.data.Store Store}, which provides multi-sort and filtering capabilities. It's
215 * easy to set up a grid to be sorted from the start:
217 * var myGrid = Ext.create('Ext.grid.Panel', {
219 * fields: ['name', 'email', 'phone'],
220 * sorters: ['name', 'phone']
223 * {text: 'Name', dataIndex: 'name'},
224 * {text: 'Email', dataIndex: 'email'}
228 * Sorting at run time is easily accomplished by simply clicking each column header. If you need to perform sorting on
229 * more than one field at run time it's easy to do so by adding new sorters to the store:
231 * myGrid.store.sort([
232 * {property: 'name', direction: 'ASC'},
233 * {property: 'email', direction: 'DESC'},
236 * {@img Ext.grid.Panel/Ext.grid.Panel4.png Ext.grid.Panel grouping}
240 * Grid supports the grouping of rows by any field. For example if we had a set of employee records, we might want to
241 * group by the department that each employee works in. Here's how we might set that up:
243 * var store = Ext.create('Ext.data.Store', {
244 * storeId:'employeeStore',
245 * fields:['name', 'senority', 'department'],
246 * groupField: 'department',
247 * data:{'employees':[
248 * {"name":"Michael Scott", "senority":7, "department":"Manangement"},
249 * {"name":"Dwight Schrute", "senority":2, "department":"Sales"},
250 * {"name":"Jim Halpert", "senority":3, "department":"Sales"},
251 * {"name":"Kevin Malone", "senority":4, "department":"Accounting"},
252 * {"name":"Angela Martin", "senority":5, "department":"Accounting"}
263 * Ext.create('Ext.grid.Panel', {
264 * title: 'Employees',
265 * store: Ext.data.StoreManager.lookup('employeeStore'),
267 * {header: 'Name', dataIndex: 'name'},
268 * {header: 'Senority', dataIndex: 'senority'}
270 * features: [{ftype:'grouping'}],
273 * renderTo: Ext.getBody()
276 * ## Infinite Scrolling
278 * Grid supports infinite scrolling as an alternative to using a paging toolbar. Your users can scroll through thousands
279 * of records without the performance penalties of renderering all the records on screen at once. The grid should be bound
280 * to a store with a pageSize specified.
282 * var grid = Ext.create('Ext.grid.Panel', {
283 * // Use a PagingGridScroller (this is interchangeable with a PagingToolbar)
284 * verticalScrollerType: 'paginggridscroller',
285 * // do not reset the scrollbar when the view refreshs
286 * invalidateScrollerOnRefresh: false,
287 * // infinite scrolling does not support selection
288 * disableSelection: true,
294 * Grid supports paging through large sets of data via a PagingToolbar or PagingGridScroller (see the Infinite Scrolling section above).
295 * To leverage paging via a toolbar or scroller, you need to set a pageSize configuration on the Store.
297 * var itemsPerPage = 2; // set the number of items you want per page
299 * var store = Ext.create('Ext.data.Store', {
300 * id:'simpsonsStore',
302 * fields:['name', 'email', 'phone'],
303 * pageSize: itemsPerPage, // items per page
306 * url: 'pagingstore.js', // url that will load data with respect to start and limit params
310 * totalProperty: 'total'
315 * // specify segment of data you want to load using params
319 * limit: itemsPerPage
323 * Ext.create('Ext.grid.Panel', {
327 * {header: 'Name', dataIndex: 'name'},
328 * {header: 'Email', dataIndex: 'email', flex:1},
329 * {header: 'Phone', dataIndex: 'phone'}
334 * xtype: 'pagingtoolbar',
335 * store: store, // same store GridPanel is using
339 * renderTo: Ext.getBody()
342 * {@img Ext.grid.Panel/Ext.grid.Panel5.png Ext.grid.Panel grouping}
344 * @docauthor Ed Spencer
346 Ext.define('Ext.grid.Panel', {
347 extend: 'Ext.panel.Table',
348 requires: ['Ext.grid.View'],
349 alias: ['widget.gridpanel', 'widget.grid'],
350 alternateClassName: ['Ext.list.ListView', 'Ext.ListView', 'Ext.grid.GridPanel'],
351 viewType: 'gridview',
355 // Required for the Lockable Mixin. These are the configurations which will be copied to the
356 // normal and locked sub tablepanels
357 normalCfgCopy: ['invalidateScrollerOnRefresh', 'verticalScroller', 'verticalScrollDock', 'verticalScrollerType', 'scroll'],
358 lockedCfgCopy: ['invalidateScrollerOnRefresh'],
361 * @cfg {Boolean} columnLines Adds column line styling
364 initComponent: function() {
367 if (me.columnLines) {
368 me.setColumnLines(me.columnLines);
374 setColumnLines: function(show) {
376 method = (show) ? 'addClsWithUI' : 'removeClsWithUI';
378 me[method]('with-col-lines')