2 * Ext JS Library 2.2.1
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
9 Ext.onReady(function() {
\r
10 var btn = Ext.get("create-grid");
\r
11 btn.on("click", function(){
\r
12 btn.dom.disabled = true;
\r
15 var grid = new Ext.grid.TableGrid("the-table", {
\r
16 stripeRows: true // stripe alternate rows
\r
19 }, false, {single:true}); // run once
\r
23 * @class Ext.grid.TableGrid
\r
24 * @extends Ext.grid.Grid
\r
25 * A Grid which creates itself from an existing HTML table element.
\r
27 * @param {String/HTMLElement/Ext.Element} table The table element from which this grid will be created -
\r
28 * The table MUST have some type of size defined for the grid to fill. The container will be
\r
29 * automatically set to position relative if it isn't already.
\r
30 * @param {Object} config A config object that sets properties on this grid and has two additional (optional)
\r
31 * properties: fields and columns which allow for customizing data fields and columns for this grid.
\r
33 * 2007-03-01 Original version by Nige "Animal" White
\r
34 * 2007-03-10 jvs Slightly refactored to reuse existing classes
\r
36 Ext.grid.TableGrid = function(table, config) {
\r
37 config = config || {};
\r
38 Ext.apply(this, config);
\r
39 var cf = config.fields || [], ch = config.columns || [];
\r
40 table = Ext.get(table);
\r
42 var ct = table.insertSibling();
\r
44 var fields = [], cols = [];
\r
45 var headers = table.query("thead th");
\r
46 for (var i = 0, h; h = headers[i]; i++) {
\r
47 var text = h.innerHTML;
\r
48 var name = 'tcol-'+i;
\r
50 fields.push(Ext.applyIf(cf[i] || {}, {
\r
52 mapping: 'td:nth('+(i+1)+')/@innerHTML'
\r
55 cols.push(Ext.applyIf(ch[i] || {}, {
\r
58 'width': h.offsetWidth,
\r
64 var ds = new Ext.data.Store({
\r
65 reader: new Ext.data.XmlReader({
\r
70 ds.loadData(table.dom);
\r
72 var cm = new Ext.grid.ColumnModel(cols);
\r
74 if (config.width || config.height) {
\r
75 ct.setSize(config.width || 'auto', config.height || 'auto');
\r
77 ct.setWidth(table.getWidth());
\r
80 if (config.remove !== false) {
\r
87 'sm': new Ext.grid.RowSelectionModel(),
\r
91 Ext.grid.TableGrid.superclass.constructor.call(this, ct, {});
\r
94 Ext.extend(Ext.grid.TableGrid, Ext.grid.GridPanel);