4 * Copyright(c) 2006-2007, Ext JS, LLC.
6 * Originally Released Under LGPL - original licence link has changed is not relivant.
9 * <script type="text/javascript">
12 Roo.BLANK_IMAGE_URL = "../../images/default/s.gif";
14 Roo.onReady(function() {
\r
15 var btn = Roo.get("create-grid");
\r
16 btn.on("click", function(){
\r
17 btn.dom.disabled = true;
\r
20 var grid = new Roo.grid.TableGrid("the-table");
\r
23 }, false, {single:true}); // run once
\r
27 * @class Roo.grid.TableGrid
\r
28 * @extends Roo.grid.Grid
\r
29 * A Grid which creates itself from an existing HTML table element.
\r
31 * @param {String/HTMLElement/Roo.Element} table The table element from which this grid will be created -
\r
32 * The table MUST have some type of size defined for the grid to fill. The container will be
\r
33 * automatically set to position relative if it isn't already.
\r
34 * @param {Object} config A config object that sets properties on this grid and has two additional (optional)
\r
35 * properties: fields and columns which allow for customizing data fields and columns for this grid.
\r
37 * 2007-03-01 Original version by Nige "Animal" White
\r
38 * 2007-03-10 jvs Slightly refactored to reuse existing classes
\r
40 Roo.grid.TableGrid = function(table, config) {
\r
41 config = config || {};
\r
42 var cf = config.fields || [], ch = config.columns || [];
\r
43 table = Roo.get(table);
\r
45 var ct = table.insertSibling();
\r
47 var fields = [], cols = [];
\r
48 var headers = table.query("thead th");
\r
49 for (var i = 0, h; h = headers[i]; i++) {
\r
50 var text = h.innerHTML;
\r
51 var name = 'tcol-'+i;
\r
53 fields.push(Roo.applyIf(cf[i] || {}, {
\r
55 mapping: 'td:nth('+(i+1)+')/@innerHTML'
\r
58 cols.push(Roo.applyIf(ch[i] || {}, {
\r
61 'width': h.offsetWidth,
\r
67 var ds = new Roo.data.Store({
\r
68 reader: new Roo.data.XmlReader({
\r
73 ds.loadData(table.dom);
\r
75 var cm = new Roo.grid.ColumnModel(cols);
\r
77 if(config.width || config.height){
\r
78 ct.setSize(config.width || 'auto', config.height || 'auto');
\r
80 if(config.remove !== false){
\r
84 Roo.grid.TableGrid.superclass.constructor.call(this, ct,
\r
85 Roo.applyIf(config, {
\r
88 'sm': new Roo.grid.RowSelectionModel(),
\r
95 Roo.extend(Roo.grid.TableGrid, Roo.grid.Grid);