]> git.proxmox.com Git - extjs.git/blame - extjs/packages/ux/classic/src/grid/TransformGrid.js
add extjs 6.0.1 sources
[extjs.git] / extjs / packages / ux / classic / src / grid / TransformGrid.js
CommitLineData
6527f429
DM
1/**\r
2 * A Grid which creates itself from an existing HTML table element.\r
3 */\r
4Ext.define('Ext.ux.grid.TransformGrid', {\r
5 extend: 'Ext.grid.Panel',\r
6\r
7 /**\r
8 * Creates the grid from HTML table element.\r
9 * @param {String/HTMLElement/Ext.Element} table The table element from which this grid will be created -\r
10 * The table MUST have some type of size defined for the grid to fill. The container will be\r
11 * automatically set to position relative if it isn't already.\r
12 * @param {Object} [config] A config object that sets properties on this grid and has two additional (optional)\r
13 * properties: fields and columns which allow for customizing data fields and columns for this grid.\r
14 */\r
15 constructor: function(table, config) {\r
16 config = Ext.apply({}, config);\r
17 table = this.table = Ext.get(table);\r
18\r
19 var configFields = config.fields || [],\r
20 configColumns = config.columns || [],\r
21 fields = [],\r
22 cols = [],\r
23 headers = table.query("thead th"),\r
24 i = 0,\r
25 len = headers.length,\r
26 data = table.dom,\r
27 width,\r
28 height,\r
29 store,\r
30 col,\r
31 text,\r
32 name;\r
33\r
34 for (; i < len; ++i) {\r
35 col = headers[i];\r
36\r
37 text = col.innerHTML;\r
38 name = 'tcol-' + i;\r
39\r
40 fields.push(Ext.applyIf(configFields[i] || {}, {\r
41 name: name,\r
42 mapping: 'td:nth(' + (i + 1) + ')/@innerHTML'\r
43 }));\r
44\r
45 cols.push(Ext.applyIf(configColumns[i] || {}, {\r
46 text: text,\r
47 dataIndex: name,\r
48 width: col.offsetWidth,\r
49 tooltip: col.title,\r
50 sortable: true\r
51 }));\r
52 }\r
53\r
54 if (config.width) {\r
55 width = config.width;\r
56 } else {\r
57 width = table.getWidth() + 1;\r
58 }\r
59\r
60 if (config.height) {\r
61 height = config.height;\r
62 }\r
63\r
64 Ext.applyIf(config, {\r
65 store: {\r
66 data: data,\r
67 fields: fields,\r
68 proxy: {\r
69 type: 'memory',\r
70 reader: {\r
71 record: 'tbody tr',\r
72 type: 'xml'\r
73 }\r
74 }\r
75 },\r
76 columns: cols,\r
77 width: width,\r
78 height: height\r
79 });\r
80 this.callParent([config]);\r
81 \r
82 if (config.remove !== false) {\r
83 // Don't use table.remove() as that destroys the row/cell data in the table in\r
84 // IE6-7 so it cannot be read by the data reader.\r
85 data.parentNode.removeChild(data);\r
86 }\r
87 },\r
88\r
89 onDestroy: function() {\r
90 this.callParent();\r
91 this.table.remove();\r
92 delete this.table;\r
93 }\r
94});