3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.com/license
15 Ext.ns('Ext.ux.grid');
18 * @class Ext.ux.grid.TableGrid
19 * @extends Ext.grid.GridPanel
20 * A Grid which creates itself from an existing HTML table element.
22 * 2007-03-01 Original version by Nige "Animal" White
23 * 2007-03-10 jvs Slightly refactored to reuse existing classes * @constructor
24 * @param {String/HTMLElement/Ext.Element} table The table element from which this grid will be created -
25 * The table MUST have some type of size defined for the grid to fill. The container will be
26 * automatically set to position relative if it isn't already.
27 * @param {Object} config A config object that sets properties on this grid and has two additional (optional)
28 * properties: fields and columns which allow for customizing data fields and columns for this grid.
30 Ext.ux.grid.TableGrid = function(table, config){
33 Ext.apply(this, config);
34 var cf = config.fields || [], ch = config.columns || [];
35 table = Ext.get(table);
37 var ct = table.insertSibling();
39 var fields = [], cols = [];
40 var headers = table.query("thead th");
41 for (var i = 0, h; h = headers[i]; i++) {
42 var text = h.innerHTML;
43 var name = 'tcol-' + i;
45 fields.push(Ext.applyIf(cf[i] ||
48 mapping: 'td:nth(' + (i + 1) + ')/@innerHTML'
51 cols.push(Ext.applyIf(ch[i] ||
55 'width': h.offsetWidth,
61 var ds = new Ext.data.Store({
62 reader: new Ext.data.XmlReader({
67 ds.loadData(table.dom);
69 var cm = new Ext.grid.ColumnModel(cols);
71 if (config.width || config.height) {
72 ct.setSize(config.width || 'auto', config.height || 'auto');
75 ct.setWidth(table.getWidth());
78 if (config.remove !== false) {
85 'sm': new Ext.grid.RowSelectionModel(),
89 Ext.ux.grid.TableGrid.superclass.constructor.call(this, ct, {});
92 Ext.extend(Ext.ux.grid.TableGrid, Ext.grid.GridPanel);
95 Ext.grid.TableGrid = Ext.ux.grid.TableGrid;