1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-grid.Panel'>/**
2 </span> * @author Aaron Conran
3 * @class Ext.grid.Panel
4 * @extends Ext.panel.Table
6 * Grids are an excellent way of showing large amounts of tabular data on the client side. Essentially a supercharged
7 * `<table>`, GridPanel makes it easy to fetch, sort and filter large amounts of data.
9 * Grids are composed of 2 main pieces - a {@link Ext.data.Store Store} full of data and a set of columns to render.
11 * {@img Ext.grid.Panel/Ext.grid.Panel1.png Ext.grid.Panel component}
15 * Ext.create('Ext.data.Store', {
16 * storeId:'simpsonsStore',
17 * fields:['name', 'email', 'phone'],
19 * {"name":"Lisa", "email":"lisa@simpsons.com", "phone":"555-111-1224"},
20 * {"name":"Bart", "email":"bart@simpsons.com", "phone":"555--222-1234"},
21 * {"name":"Homer", "email":"home@simpsons.com", "phone":"555-222-1244"},
22 * {"name":"Marge", "email":"marge@simpsons.com", "phone":"555-222-1254"}
33 * Ext.create('Ext.grid.Panel', {
35 * store: Ext.data.StoreManager.lookup('simpsonsStore'),
37 * {header: 'Name', dataIndex: 'name'},
38 * {header: 'Email', dataIndex: 'email', flex:1},
39 * {header: 'Phone', dataIndex: 'phone'}
43 * renderTo: Ext.getBody()
46 * The code above produces a simple grid with three columns. We specified a Store which will load JSON data inline.
47 * In most apps we would be placing the grid inside another container and wouldn't need to use the
48 * {@link #height}, {@link #width} and {@link #renderTo} configurations but they are included here to make it easy to get
51 * The grid we created above will contain a header bar with a title ('Simpsons'), a row of column headers directly underneath
52 * and finally the grid rows under the headers.
54 * ## Configuring columns
56 * By default, each column is sortable and will toggle between ASC and DESC sorting when you click on its header. Each
57 * column header is also reorderable by default, and each gains a drop-down menu with options to hide and show columns.
58 * It's easy to configure each column - here we use the same example as above and just modify the columns config:
80 * We turned off sorting and hiding on the 'Name' column so clicking its header now has no effect. We also made the Email
81 * column hidden by default (it can be shown again by using the menu on any other column). We also set the Phone column to
82 * a fixed with of 100px and flexed the Name column, which means it takes up all remaining width after the other columns
83 * have been accounted for. See the {@link Ext.grid.column.Column column docs} for more details.
87 * As well as customizing columns, it's easy to alter the rendering of individual cells using renderers. A renderer is
88 * tied to a particular column and is passed the value that would be rendered into each cell in that column. For example,
89 * we could define a renderer function for the email column to turn each email address into a mailto link:
95 * renderer: function(value) {
96 * return Ext.String.format('<a href="mailto:{0}">{1}</a>', value, value);
101 * See the {@link Ext.grid.column.Column column docs} for more information on renderers.
103 * ## Selection Models
105 * Sometimes all you want is to render data onto the screen for viewing, but usually it's necessary to interact with or
106 * update that data. Grids use a concept called a Selection Model, which is simply a mechanism for selecting some part of
107 * the data in the grid. The two main types of Selection Model are RowSelectionModel, where entire rows are selected, and
108 * CellSelectionModel, where individual cells are selected.
110 * Grids use a Row Selection Model by default, but this is easy to customise like so:
112 * Ext.create('Ext.grid.Panel', {
113 * selType: 'cellmodel',
117 * Specifying the `cellmodel` changes a couple of things. Firstly, clicking on a cell now
118 * selects just that cell (using a {@link Ext.selection.RowModel rowmodel} will select the entire row), and secondly the
119 * keyboard navigation will walk from cell to cell instead of row to row. Cell-based selection models are usually used in
120 * conjunction with editing.
122 * {@img Ext.grid.Panel/Ext.grid.Panel2.png Ext.grid.Panel cell editing}
126 * Grid has built-in support for in-line editing. There are two chief editing modes - cell editing and row editing. Cell
127 * editing is easy to add to your existing column setup - here we'll just modify the example above to include an editor
128 * on both the name and the email columns:
130 * Ext.create('Ext.grid.Panel', {
132 * store: Ext.data.StoreManager.lookup('simpsonsStore'),
134 * {header: 'Name', dataIndex: 'name', field: 'textfield'},
135 * {header: 'Email', dataIndex: 'email', flex:1,
141 * {header: 'Phone', dataIndex: 'phone'}
143 * selType: 'cellmodel',
145 * Ext.create('Ext.grid.plugin.CellEditing', {
151 * renderTo: Ext.getBody()
154 * This requires a little explanation. We're passing in {@link #store store} and {@link #columns columns} as normal, but
155 * this time we've also specified a {@link #field field} on two of our columns. For the Name column we just want a default
156 * textfield to edit the value, so we specify 'textfield'. For the Email column we customized the editor slightly by
157 * passing allowBlank: false, which will provide inline validation.
159 * To support cell editing, we also specified that the grid should use the 'cellmodel' {@link #selType}, and created an
160 * instance of the {@link Ext.grid.plugin.CellEditing CellEditing plugin}, which we configured to activate each editor after a
163 * {@img Ext.grid.Panel/Ext.grid.Panel3.png Ext.grid.Panel row editing}
167 * The other type of editing is row-based editing, using the RowEditor component. This enables you to edit an entire row
168 * at a time, rather than editing cell by cell. Row Editing works in exactly the same way as cell editing, all we need to
169 * do is change the plugin type to {@link Ext.grid.plugin.RowEditing}, and set the selType to 'rowmodel':
171 * Ext.create('Ext.grid.Panel', {
173 * store: Ext.data.StoreManager.lookup('simpsonsStore'),
175 * {header: 'Name', dataIndex: 'name', field: 'textfield'},
176 * {header: 'Email', dataIndex: 'email', flex:1,
182 * {header: 'Phone', dataIndex: 'phone'}
184 * selType: 'rowmodel',
186 * Ext.create('Ext.grid.plugin.RowEditing', {
192 * renderTo: Ext.getBody()
195 * Again we passed some configuration to our {@link Ext.grid.plugin.RowEditing} plugin, and now when we click each row a row
196 * editor will appear and enable us to edit each of the columns we have specified an editor for.
198 * ## Sorting & Filtering
200 * Every grid is attached to a {@link Ext.data.Store Store}, which provides multi-sort and filtering capabilities. It's
201 * easy to set up a grid to be sorted from the start:
203 * var myGrid = Ext.create('Ext.grid.Panel', {
205 * fields: ['name', 'email', 'phone'],
206 * sorters: ['name', 'phone']
209 * {text: 'Name', dataIndex: 'name'},
210 * {text: 'Email', dataIndex: 'email'}
214 * Sorting at run time is easily accomplished by simply clicking each column header. If you need to perform sorting on
215 * more than one field at run time it's easy to do so by adding new sorters to the store:
217 * myGrid.store.sort([
218 * {property: 'name', direction: 'ASC'},
219 * {property: 'email', direction: 'DESC'},
222 * {@img Ext.grid.Panel/Ext.grid.Panel4.png Ext.grid.Panel grouping}
226 * Grid supports the grouping of rows by any field. For example if we had a set of employee records, we might want to
227 * group by the department that each employee works in. Here's how we might set that up:
229 * var store = Ext.create('Ext.data.Store', {
230 * storeId:'employeeStore',
231 * fields:['name', 'senority', 'department'],
232 * groupField: 'department',
233 * data:{'employees':[
234 * {"name":"Michael Scott", "senority":7, "department":"Manangement"},
235 * {"name":"Dwight Schrute", "senority":2, "department":"Sales"},
236 * {"name":"Jim Halpert", "senority":3, "department":"Sales"},
237 * {"name":"Kevin Malone", "senority":4, "department":"Accounting"},
238 * {"name":"Angela Martin", "senority":5, "department":"Accounting"}
249 * Ext.create('Ext.grid.Panel', {
250 * title: 'Employees',
251 * store: Ext.data.StoreManager.lookup('employeeStore'),
253 * {header: 'Name', dataIndex: 'name'},
254 * {header: 'Senority', dataIndex: 'senority'}
256 * features: [{ftype:'grouping'}],
259 * renderTo: Ext.getBody()
262 * ## Infinite Scrolling
264 * Grid supports infinite scrolling as an alternative to using a paging toolbar. Your users can scroll through thousands
265 * of records without the performance penalties of renderering all the records on screen at once. The grid should be bound
266 * to a store with a pageSize specified.
268 * var grid = Ext.create('Ext.grid.Panel', {
269 * // Use a PagingGridScroller (this is interchangeable with a PagingToolbar)
270 * verticalScrollerType: 'paginggridscroller',
271 * // do not reset the scrollbar when the view refreshs
272 * invalidateScrollerOnRefresh: false,
273 * // infinite scrolling does not support selection
274 * disableSelection: true,
280 * Grid supports paging through large sets of data via a PagingToolbar or PagingGridScroller (see the Infinite Scrolling section above).
281 * To leverage paging via a toolbar or scroller, you need to set a pageSize configuration on the Store.
283 * var itemsPerPage = 2; // set the number of items you want per page
285 * var store = Ext.create('Ext.data.Store', {
286 * id:'simpsonsStore',
288 * fields:['name', 'email', 'phone'],
289 * pageSize: itemsPerPage, // items per page
292 * url: 'pagingstore.js', // url that will load data with respect to start and limit params
296 * totalProperty: 'total'
301 * // specify segment of data you want to load using params
305 * limit: itemsPerPage
309 * Ext.create('Ext.grid.Panel', {
313 * {header: 'Name', dataIndex: 'name'},
314 * {header: 'Email', dataIndex: 'email', flex:1},
315 * {header: 'Phone', dataIndex: 'phone'}
320 * xtype: 'pagingtoolbar',
321 * store: store, // same store GridPanel is using
325 * renderTo: Ext.getBody()
328 * {@img Ext.grid.Panel/Ext.grid.Panel5.png Ext.grid.Panel grouping}
330 * @docauthor Ed Spencer
332 Ext.define('Ext.grid.Panel', {
333 extend: 'Ext.panel.Table',
334 requires: ['Ext.grid.View'],
335 alias: ['widget.gridpanel', 'widget.grid'],
336 alternateClassName: ['Ext.list.ListView', 'Ext.ListView', 'Ext.grid.GridPanel'],
337 viewType: 'gridview',
341 // Required for the Lockable Mixin. These are the configurations which will be copied to the
342 // normal and locked sub tablepanels
343 normalCfgCopy: ['invalidateScrollerOnRefresh', 'verticalScroller', 'verticalScrollDock', 'verticalScrollerType', 'scroll'],
344 lockedCfgCopy: ['invalidateScrollerOnRefresh'],
346 <span id='Ext-grid.Panel-cfg-columnLines'> /**
347 </span> * @cfg {Boolean} columnLines Adds column line styling
350 initComponent: function() {
353 if (me.columnLines) {
354 me.setColumnLines(me.columnLines);
360 setColumnLines: function(show) {
362 method = (show) ? 'addClsWithUI' : 'removeClsWithUI';
364 me[method]('with-col-lines')
366 });</pre></pre></body></html>