Repository navigation
Expand file tree
/
Copy pathrows.html
More file actions
223 lines (195 loc) · 6.96 KB
/
Copy pathrows.html
File metadata and controls
223 lines (195 loc) · 6.96 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<button>Add row</button> <button>Remove row</button>
<hr />
<div id="idSelect"></div>
<hr />
<div id="idResult" style="height: 200px; width: 400px; overflow: scroll;"></div>
<script type="module">
import { CTableData, browser } from "./lib/TableData.js";
import { edit } from "./lib/TableDataEdit.js";
import { CTableDataTrigger } from "./lib/TableDataTrigger.js";
import { CUITableText } from "./lib/UITableText.js";
window.edit = edit;
window.CTableData = CTableData;
window.CTableData_browser = browser;
window.CUITableText = CUITableText;
window.CTableDataTrigger = CTableDataTrigger;
</script>
<script>
function render_select(sId, aResult) {
let aData = aResult[ 0 ];
let aPosition = aResult[ 1 ];
let eDocument = new DocumentFragment(); // document fragment collects elements before insert to DOM
let eSelect = document.createElement("select"); // select element for dropdown created
eSelect.appendChild(document.createElement("option")); // add empty value first
aData.forEach((a, i) => {
let eOption = document.createElement("option"); // selectable option item
eOption.value = a[ 0 ]; // ID // ID value to text
eOption.appendChild(document.createTextNode(a[ 1 ])) // add readable text to option
eOption.dataset.index = aPosition[ i ].toString(); // custom attribute using "data-" format
eSelect.appendChild(eOption); // add to select
});
eDocument.appendChild(eSelect); // add all to the document fragment
// create event to trigger change
eSelect.addEventListener("change", event => {
let eSelect = event.srcElement; console.assert(eSelect.tagName === "SELECT", "No Select element, this is wrong!");
let eOption = eSelect.options[ eSelect.selectedIndex ];
console.log(`Tag name is ${eOption.tagName} and data-index is ${eOption.dataset.index}`);
});
// finaly insert to dom tree, when this is done the elements are moved from document fragment into dom tree
document.getElementById(sId).appendChild(eDocument);
}
</script>
<script>
function setup() {
CTableData_browser.AddCSS(sCSS); // prepare CSS
let tabledataTest = new CTableData();
tabledataTest.ReadObjects(json);
let tabledataTest2 = new CTableData();
tabledataTest2.ReadObjects(json);
tabledataTest.ROWAppend(tabledataTest2.GetData()[ 0 ]);
tabledataTest.ROWRemove(6, 5);
tabledataTest.ROWAppend(tabledataTest2.GetData()[ 0 ]);
let aResult = tabledataTest.GetData();
console.table(aResult[ 0 ]);
console.table(aResult[ 1 ]);
render_select("idSelect", aResult);
let oTrigger = new CTableDataTrigger({ table: tabledataTest, trigger: callbackTableData });
let oTableText = new CUITableText({
action: callbackTable,
edit: true,
parent: document.getElementById("idResult"),
section: [ "toolbar", "title", "table.header", "table.body", "table.footer", "statusbar" ],
table: tabledataTest,
trigger: oTrigger
});
oTableText.Render();
let aWidth = oTableText.COLUMNCalculateMaxWidth("body", null, 1); console.log(aWidth);
oTableText.COLUMNSetWidth(aWidth, "header");
}
function callbackTableData(iTrigger, iReason, data) {
console.log("Trigger:", iTrigger, " Reason:", iReason);
iTrigger = iTrigger & 0xffff; console.log(iTrigger);
}
function callbackTable(sEventType, event, sSection) {
console.log(sEventType, sSection);
}
</script>
<script>
document.addEventListener('DOMContentLoaded', function() {
setup();
});
let sCSS = `
.uitabletext { display: table; width: 100%; }
.uitabletext > div { display: table-row; }
.uitabletext > div > span { display: table-cell; padding: 5px; border-bottom: thin solid #ddd; border-left: thin solid #ddd; }
[data-group="table"] > section.uitabletext-header { position: sticky; top: 0;}
.uitabletext .input { border: 1px solid grey; }
.uitabletext .selected { border: 1px solid grey; }
`;
let json = [
{
"ID": 32,
"Name": "Neighborhood",
"act": 0,
"req": 0,
"prj": 0,
"book": 0,
"todo": "0 : 0"
},
{
"ID": 30,
"Name": "Selection - Systems",
"act": 0,
"req": 0,
"prj": 0,
"book": 0,
"todo": "0 : 0"
},
{
"ID": 1,
"Name": "SuperOffice database script",
"act": 0,
"req": 0,
"prj": 0,
"book": 0,
"todo": "0 : 0"
},
{
"ID": 4,
"Name": "Select core component",
"act": 0,
"req": 0,
"prj": 0,
"book": 0,
"todo": "0 : 0"
},
{
"ID": 58,
"Name": "Sample projects",
"act": 0,
"req": 0,
"prj": 0,
"book": 0,
"todo": "0 : 0"
},
{
"ID": 3077,
"Name": "TEST",
"act": 3,
"req": 2,
"prj": 7,
"book": 1,
"todo": "1 : 3"
},
{
"ID": 3090,
"Name": "Applications, tips, reviews, etc",
"act": 0,
"req": 0,
"prj": 0,
"book": 1,
"todo": "0 : 0",
"Type": "Application"
},
{
"ID": 3094,
"Name": "Garden crops",
"act": 0,
"req": 0,
"prj": 0,
"book": 2,
"todo": "0 : 0"
},
{
"ID": 3,
"Name": "Selection - Standard dashboards and components",
"act": 0,
"req": 0,
"prj": 0,
"book": 0,
"todo": "0 : 0",
"Thread": "Dashboards"
},
{
"ID": 47,
"Name": "rSelect",
"act": 11,
"req": 3,
"prj": 4,
"book": 6,
"todo": "0 : 0",
"Description": "#rselect",
"Type": "Script",
"Thread": "Dashboards"
}
];
</script>
</body>
</html>