4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-grid-Panel'>/**
19 </span> * @author Aaron Conran
20 * @class Ext.grid.Panel
21 * @extends Ext.panel.Table
23 * Grids are an excellent way of showing large amounts of tabular data on the client side. Essentially a supercharged
24 * `<table>`, GridPanel makes it easy to fetch, sort and filter large amounts of data.
26 * Grids are composed of 2 main pieces - a {@link Ext.data.Store Store} full of data and a set of columns to render.
28 * {@img Ext.grid.Panel/Ext.grid.Panel1.png Ext.grid.Panel component}
32 * Ext.create('Ext.data.Store', {
33 * storeId:'simpsonsStore',
34 * fields:['name', 'email', 'phone'],
36 * {"name":"Lisa", "email":"lisa@simpsons.com", "phone":"555-111-1224"},
37 * {"name":"Bart", "email":"bart@simpsons.com", "phone":"555--222-1234"},
38 * {"name":"Homer", "email":"home@simpsons.com", "phone":"555-222-1244"},
39 * {"name":"Marge", "email":"marge@simpsons.com", "phone":"555-222-1254"}
50 * Ext.create('Ext.grid.Panel', {
52 * store: Ext.data.StoreManager.lookup('simpsonsStore'),
54 * {header: 'Name', dataIndex: 'name'},
55 * {header: 'Email', dataIndex: 'email', flex:1},
56 * {header: 'Phone', dataIndex: 'phone'}
60 * renderTo: Ext.getBody()
63 * The code above produces a simple grid with three columns. We specified a Store which will load JSON data inline.
64 * In most apps we would be placing the grid inside another container and wouldn't need to use the
65 * {@link #height}, {@link #width} and {@link #renderTo} configurations but they are included here to make it easy to get
68 * The grid we created above will contain a header bar with a title ('Simpsons'), a row of column headers directly underneath
69 * and finally the grid rows under the headers.
71 * ## Configuring columns
73 * By default, each column is sortable and will toggle between ASC and DESC sorting when you click on its header. Each
74 * column header is also reorderable by default, and each gains a drop-down menu with options to hide and show columns.
75 * It's easy to configure each column - here we use the same example as above and just modify the columns config:
97 * We turned off sorting and hiding on the 'Name' column so clicking its header now has no effect. We also made the Email
98 * column hidden by default (it can be shown again by using the menu on any other column). We also set the Phone column to
99 * a fixed with of 100px and flexed the Name column, which means it takes up all remaining width after the other columns
100 * have been accounted for. See the {@link Ext.grid.column.Column column docs} for more details.
104 * As well as customizing columns, it's easy to alter the rendering of individual cells using renderers. A renderer is
105 * tied to a particular column and is passed the value that would be rendered into each cell in that column. For example,
106 * we could define a renderer function for the email column to turn each email address into a mailto link:
111 * dataIndex: 'email',
112 * renderer: function(value) {
113 * return Ext.String.format('<a href="mailto:{0}">{1}</a>', value, value);
118 * See the {@link Ext.grid.column.Column column docs} for more information on renderers.
120 * ## Selection Models
122 * Sometimes all you want is to render data onto the screen for viewing, but usually it's necessary to interact with or
123 * update that data. Grids use a concept called a Selection Model, which is simply a mechanism for selecting some part of
124 * the data in the grid. The two main types of Selection Model are RowSelectionModel, where entire rows are selected, and
125 * CellSelectionModel, where individual cells are selected.
127 * Grids use a Row Selection Model by default, but this is easy to customise like so:
129 * Ext.create('Ext.grid.Panel', {
130 * selType: 'cellmodel',
134 * Specifying the `cellmodel` changes a couple of things. Firstly, clicking on a cell now
135 * selects just that cell (using a {@link Ext.selection.RowModel rowmodel} will select the entire row), and secondly the
136 * keyboard navigation will walk from cell to cell instead of row to row. Cell-based selection models are usually used in
137 * conjunction with editing.
139 * {@img Ext.grid.Panel/Ext.grid.Panel2.png Ext.grid.Panel cell editing}
143 * Grid has built-in support for in-line editing. There are two chief editing modes - cell editing and row editing. Cell
144 * editing is easy to add to your existing column setup - here we'll just modify the example above to include an editor
145 * on both the name and the email columns:
147 * Ext.create('Ext.grid.Panel', {
149 * store: Ext.data.StoreManager.lookup('simpsonsStore'),
151 * {header: 'Name', dataIndex: 'name', field: 'textfield'},
152 * {header: 'Email', dataIndex: 'email', flex:1,
158 * {header: 'Phone', dataIndex: 'phone'}
160 * selType: 'cellmodel',
162 * Ext.create('Ext.grid.plugin.CellEditing', {
168 * renderTo: Ext.getBody()
171 * This requires a little explanation. We're passing in {@link #store store} and {@link #columns columns} as normal, but
172 * this time we've also specified a {@link #field field} on two of our columns. For the Name column we just want a default
173 * textfield to edit the value, so we specify 'textfield'. For the Email column we customized the editor slightly by
174 * passing allowBlank: false, which will provide inline validation.
176 * To support cell editing, we also specified that the grid should use the 'cellmodel' {@link #selType}, and created an
177 * instance of the {@link Ext.grid.plugin.CellEditing CellEditing plugin}, which we configured to activate each editor after a
180 * {@img Ext.grid.Panel/Ext.grid.Panel3.png Ext.grid.Panel row editing}
184 * The other type of editing is row-based editing, using the RowEditor component. This enables you to edit an entire row
185 * at a time, rather than editing cell by cell. Row Editing works in exactly the same way as cell editing, all we need to
186 * do is change the plugin type to {@link Ext.grid.plugin.RowEditing}, and set the selType to 'rowmodel':
188 * Ext.create('Ext.grid.Panel', {
190 * store: Ext.data.StoreManager.lookup('simpsonsStore'),
192 * {header: 'Name', dataIndex: 'name', field: 'textfield'},
193 * {header: 'Email', dataIndex: 'email', flex:1,
199 * {header: 'Phone', dataIndex: 'phone'}
201 * selType: 'rowmodel',
203 * Ext.create('Ext.grid.plugin.RowEditing', {
209 * renderTo: Ext.getBody()
212 * Again we passed some configuration to our {@link Ext.grid.plugin.RowEditing} plugin, and now when we click each row a row
213 * editor will appear and enable us to edit each of the columns we have specified an editor for.
215 * ## Sorting & Filtering
217 * Every grid is attached to a {@link Ext.data.Store Store}, which provides multi-sort and filtering capabilities. It's
218 * easy to set up a grid to be sorted from the start:
220 * var myGrid = Ext.create('Ext.grid.Panel', {
222 * fields: ['name', 'email', 'phone'],
223 * sorters: ['name', 'phone']
226 * {text: 'Name', dataIndex: 'name'},
227 * {text: 'Email', dataIndex: 'email'}
231 * Sorting at run time is easily accomplished by simply clicking each column header. If you need to perform sorting on
232 * more than one field at run time it's easy to do so by adding new sorters to the store:
234 * myGrid.store.sort([
235 * {property: 'name', direction: 'ASC'},
236 * {property: 'email', direction: 'DESC'},
239 * {@img Ext.grid.Panel/Ext.grid.Panel4.png Ext.grid.Panel grouping}
243 * Grid supports the grouping of rows by any field. For example if we had a set of employee records, we might want to
244 * group by the department that each employee works in. Here's how we might set that up:
246 * var store = Ext.create('Ext.data.Store', {
247 * storeId:'employeeStore',
248 * fields:['name', 'senority', 'department'],
249 * groupField: 'department',
250 * data:{'employees':[
251 * {"name":"Michael Scott", "senority":7, "department":"Manangement"},
252 * {"name":"Dwight Schrute", "senority":2, "department":"Sales"},
253 * {"name":"Jim Halpert", "senority":3, "department":"Sales"},
254 * {"name":"Kevin Malone", "senority":4, "department":"Accounting"},
255 * {"name":"Angela Martin", "senority":5, "department":"Accounting"}
266 * Ext.create('Ext.grid.Panel', {
267 * title: 'Employees',
268 * store: Ext.data.StoreManager.lookup('employeeStore'),
270 * {header: 'Name', dataIndex: 'name'},
271 * {header: 'Senority', dataIndex: 'senority'}
273 * features: [{ftype:'grouping'}],
276 * renderTo: Ext.getBody()
279 * ## Infinite Scrolling
281 * Grid supports infinite scrolling as an alternative to using a paging toolbar. Your users can scroll through thousands
282 * of records without the performance penalties of renderering all the records on screen at once. The grid should be bound
283 * to a store with a pageSize specified.
285 * var grid = Ext.create('Ext.grid.Panel', {
286 * // Use a PagingGridScroller (this is interchangeable with a PagingToolbar)
287 * verticalScrollerType: 'paginggridscroller',
288 * // do not reset the scrollbar when the view refreshs
289 * invalidateScrollerOnRefresh: false,
290 * // infinite scrolling does not support selection
291 * disableSelection: true,
297 * Grid supports paging through large sets of data via a PagingToolbar or PagingGridScroller (see the Infinite Scrolling section above).
298 * To leverage paging via a toolbar or scroller, you need to set a pageSize configuration on the Store.
300 * var itemsPerPage = 2; // set the number of items you want per page
302 * var store = Ext.create('Ext.data.Store', {
303 * id:'simpsonsStore',
305 * fields:['name', 'email', 'phone'],
306 * pageSize: itemsPerPage, // items per page
309 * url: 'pagingstore.js', // url that will load data with respect to start and limit params
313 * totalProperty: 'total'
318 * // specify segment of data you want to load using params
322 * limit: itemsPerPage
326 * Ext.create('Ext.grid.Panel', {
330 * {header: 'Name', dataIndex: 'name'},
331 * {header: 'Email', dataIndex: 'email', flex:1},
332 * {header: 'Phone', dataIndex: 'phone'}
337 * xtype: 'pagingtoolbar',
338 * store: store, // same store GridPanel is using
342 * renderTo: Ext.getBody()
345 * {@img Ext.grid.Panel/Ext.grid.Panel5.png Ext.grid.Panel grouping}
347 * @docauthor Ed Spencer
349 Ext.define('Ext.grid.Panel', {
350 extend: 'Ext.panel.Table',
351 requires: ['Ext.grid.View'],
352 alias: ['widget.gridpanel', 'widget.grid'],
353 alternateClassName: ['Ext.list.ListView', 'Ext.ListView', 'Ext.grid.GridPanel'],
354 viewType: 'gridview',
358 // Required for the Lockable Mixin. These are the configurations which will be copied to the
359 // normal and locked sub tablepanels
360 normalCfgCopy: ['invalidateScrollerOnRefresh', 'verticalScroller', 'verticalScrollDock', 'verticalScrollerType', 'scroll'],
361 lockedCfgCopy: ['invalidateScrollerOnRefresh'],
363 <span id='Ext-grid-Panel-cfg-columnLines'> /**
364 </span> * @cfg {Boolean} columnLines Adds column line styling
367 initComponent: function() {
370 if (me.columnLines) {
371 me.setColumnLines(me.columnLines);
377 setColumnLines: function(show) {
379 method = (show) ? 'addClsWithUI' : 'removeClsWithUI';
381 me[method]('with-col-lines')