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