kempo 2.9.2 → 2.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Accordion.js +1 -1
- package/dist/components/Dialog.js +1 -1
- package/dist/components/DirectoryViewer.js +1 -1
- package/dist/components/FocusCapture.js +1 -1
- package/dist/components/Icon.js +1 -1
- package/dist/components/Search.js +1 -1
- package/dist/components/Table.js +1 -1
- package/dist/components/Timestamp.js +1 -1
- package/dist/components/Toggle.js +1 -1
- package/dist/components/tableControls/DeleteSelected.js +1 -1
- package/dist/components/tableControls/Edit.js +1 -0
- package/dist/components/tableControls/Filters.js +1 -0
- package/dist/components/tableControls/HiddenCount.js +1 -0
- package/dist/components/tableControls/Hide.js +1 -0
- package/dist/components/tableControls/PageSelect.js +1 -1
- package/dist/components/tableControls/PageSize.js +1 -1
- package/dist/components/tableControls/ShowAll.js +1 -0
- package/dist/index.js +1 -1
- package/dist/kempo-styles.css +1 -1
- package/dist/kempo-vars.css +1 -1
- package/dist/utils/formatTimestamp.js +1 -1
- package/docs/components/_template.html +9 -0
- package/docs/components/accordion.html +52 -12
- package/docs/components/card.html +68 -8
- package/docs/components/component.html +6 -0
- package/docs/components/content-slider.html +8 -0
- package/docs/components/dialog.html +145 -5
- package/docs/components/directory-viewer.html +51 -40
- package/docs/components/focus-capture.html +68 -0
- package/docs/components/icon.html +76 -5
- package/docs/components/import.html +47 -0
- package/docs/components/lazy-component.html +45 -15
- package/docs/components/reactive-component.html +69 -0
- package/docs/components/reactive-lazy-component.html +69 -0
- package/docs/components/resize.html +52 -3
- package/docs/components/search.html +102 -0
- package/docs/components/show-more.html +54 -5
- package/docs/components/{sidemenu.html → side-menu.html} +56 -3
- package/docs/components/split.html +57 -16
- package/docs/components/table.html +90 -189
- package/docs/components/tableControls.html +91 -0
- package/docs/components/tableCustomFields.html +112 -0
- package/docs/components/tablePagination.html +92 -0
- package/docs/components/tableRecordEditing.html +144 -0
- package/docs/components/tableRecordFiltering.html +82 -0
- package/docs/components/tableRecordHiding.html +84 -0
- package/docs/components/tableRecordSelection.html +86 -0
- package/docs/components/tableRowControls.html +103 -0
- package/docs/components/tabs.html +72 -4
- package/docs/components/tags.html +94 -0
- package/docs/components/theme-switcher.html +74 -0
- package/docs/components/timestamp.html +86 -0
- package/docs/components/toggle.html +37 -34
- package/docs/icons/check.svg +1 -0
- package/docs/icons/hide.svg +1 -0
- package/docs/icons/show.svg +1 -0
- package/docs/index.html +5 -0
- package/docs/kempo/components/Accordion.js +1 -1
- package/docs/kempo/components/Dialog.js +1 -1
- package/docs/kempo/components/DirectoryViewer.js +1 -1
- package/docs/kempo/components/FocusCapture.js +1 -1
- package/docs/kempo/components/Icon.js +1 -1
- package/docs/kempo/components/Search.js +1 -1
- package/docs/kempo/components/Table.js +1 -1
- package/docs/kempo/components/Timestamp.js +1 -1
- package/docs/kempo/components/Toggle.js +1 -1
- package/docs/kempo/components/tableControls/DeleteSelected.js +1 -1
- package/docs/kempo/components/tableControls/Edit.js +1 -0
- package/docs/kempo/components/tableControls/Filters.js +1 -0
- package/docs/kempo/components/tableControls/HiddenCount.js +1 -0
- package/docs/kempo/components/tableControls/Hide.js +1 -0
- package/docs/kempo/components/tableControls/PageSelect.js +1 -1
- package/docs/kempo/components/tableControls/PageSize.js +1 -1
- package/docs/kempo/components/tableControls/ShowAll.js +1 -0
- package/docs/kempo/index.js +1 -1
- package/docs/kempo/kempo-styles.css +1 -1
- package/docs/kempo/kempo-vars.css +1 -1
- package/docs/kempo/utils/formatTimestamp.js +1 -1
- package/docs/nav-1.inc.html +16 -2
- package/docs/nav.inc.html +10 -2
- package/docs/search.json +281 -23
- package/docs/styles/_template.html +6 -0
- package/docs/styles/borders-spacing.html +6 -0
- package/docs/styles/buttons.html +6 -0
- package/docs/styles/colors.html +6 -0
- package/docs/styles/displays-layouts.html +6 -0
- package/docs/styles/embed-1.html +6 -0
- package/docs/styles/inputs.html +6 -0
- package/docs/styles/tables.html +6 -0
- package/docs/styles/typography.html +6 -0
- package/docs/{components/stacks.html → utils/_template.html} +11 -30
- package/docs/utils/cli.html +84 -0
- package/docs/utils/cookie.html +87 -0
- package/docs/utils/debounce.html +61 -0
- package/docs/utils/drag.html +85 -0
- package/docs/utils/element.html +124 -0
- package/docs/utils/format-timestamp.html +64 -0
- package/docs/utils/fuzzy-match.html +60 -0
- package/icons/check.svg +1 -0
- package/icons/hide.svg +1 -0
- package/icons/show.svg +1 -0
- package/package.json +1 -1
- package/src/components/Accordion.js +0 -1
- package/src/components/Dialog.js +15 -6
- package/src/components/DirectoryViewer.js +21 -92
- package/src/components/FocusCapture.js +2 -1
- package/src/components/Icon.js +3 -1
- package/src/components/Search.js +4 -1
- package/src/components/Table.js +469 -139
- package/src/components/Timestamp.js +7 -4
- package/src/components/Toggle.js +3 -0
- package/src/components/tableControls/DeleteSelected.js +36 -22
- package/src/components/tableControls/Edit.js +88 -0
- package/src/components/tableControls/Filters.js +128 -0
- package/src/components/tableControls/HiddenCount.js +42 -0
- package/src/components/tableControls/Hide.js +43 -0
- package/src/components/tableControls/PageSelect.js +54 -30
- package/src/components/tableControls/PageSize.js +33 -16
- package/src/components/tableControls/ShowAll.js +40 -0
- package/src/kempo-styles.css +7 -0
- package/src/kempo-vars.css +2 -0
- package/src/utils/formatTimestamp.js +26 -10
- package/docs/table.html +0 -0
- package/src/components/Stacks.js +0 -79
- package/src/utils/files.js +0 -15
|
@@ -4,9 +4,16 @@
|
|
|
4
4
|
<meta charset="UTF-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
6
|
<title>Table - Components - Kempo Docs - A Web Components Solution</title>
|
|
7
|
-
<link rel="stylesheet" href="../kempo/kempo-vars.css"
|
|
7
|
+
<link rel="stylesheet" href="../kempo/kempo-vars.css" />
|
|
8
|
+
<link rel="stylesheet" href="../kempo/kempo-styles.css" />
|
|
8
9
|
<link rel="stylesheet" href="../kempo/kempo-hljs.css" />
|
|
9
10
|
<script type="module" src="../kempo/components/Table.js"></script>
|
|
11
|
+
<script type="module">
|
|
12
|
+
import Icon from '../kempo/components/Icon.js';
|
|
13
|
+
import Search from '../kempo/components/Search.js';
|
|
14
|
+
Icon.pathToIcons = ['../icons'];
|
|
15
|
+
Search.searchDataUrl = '../search.json';
|
|
16
|
+
</script>
|
|
10
17
|
<script>
|
|
11
18
|
|
|
12
19
|
window.contacts = [];
|
|
@@ -57,10 +64,14 @@
|
|
|
57
64
|
<div class="m mt0 pl">
|
|
58
65
|
<h6>Examples</h6>
|
|
59
66
|
<a href="#basicUsage">Basic Usage</a><br />
|
|
60
|
-
<a href="
|
|
61
|
-
<a href="
|
|
62
|
-
<a href="
|
|
63
|
-
<a href="
|
|
67
|
+
<a href="tableCustomFields.html">Custom Fields</a><br />
|
|
68
|
+
<a href="tableControls.html">Top and Bottom Controls</a><br />
|
|
69
|
+
<a href="tableRowControls.html">Row Controls</a><br />
|
|
70
|
+
<a href="tablePagination.html">Pagination</a><br />
|
|
71
|
+
<a href="tableRecordSelection.html">Record Selection</a><br />
|
|
72
|
+
<a href="tableRecordEditing.html">Record Editing</a><br />
|
|
73
|
+
<a href="tableRecordHiding.html">Record Hiding</a><br />
|
|
74
|
+
<a href="tableRecordFiltering.html">Record Filtering</a><br />
|
|
64
75
|
<h6 class="mt">JavaScript Reference</h6>
|
|
65
76
|
<a href="#constructor">Constructor</a><br />
|
|
66
77
|
<a href="#requirements">Requirements</a><br />
|
|
@@ -108,184 +119,20 @@
|
|
|
108
119
|
});
|
|
109
120
|
</script>
|
|
110
121
|
|
|
111
|
-
<h3
|
|
112
|
-
<p>Use the <code>fields</code> property of the options object in <code>setData</code> to define custom fields. This is useful for hiding fields, reordering fields, changing the labels, formatting the output, or creating a calculated field.</p>
|
|
113
|
-
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">k-table</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"customFieldsExample"</span>></span><span class="hljs-tag"></<span class="hljs-name">k-table</span>></span><br /><span class="hljs-tag"><<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>></span><span class="javascript"><br /> <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'customFieldsExample'</span>).setData({<br /> records: contacts.slice(<span class="hljs-number">0</span>,<span class="hljs-number">10</span>),<br /> fields: [<br /> {<br /> <span class="hljs-attr">name</span>: <span class="hljs-string">"name"</span>,<br /> <span class="hljs-attr">label</span>: <span class="hljs-string">"Name"</span><br /> },<br /> {<br /> <span class="hljs-attr">name</span>: <span class="hljs-string">'phoneNumber'</span>,<br /> <span class="hljs-attr">label</span>: <span class="hljs-string">'Phone Number'</span><br /> },<br /> {<br /> <span class="hljs-attr">name</span>: <span class="hljs-string">'email'</span>,<br /> <span class="hljs-attr">label</span>: <span class="hljs-string">'Email Address'</span><br /> },<br /> {<br /> <span class="hljs-attr">name</span>: <span class="hljs-string">'birthday'</span>,<br /> <span class="hljs-attr">label</span>: <span class="hljs-string">'Birthday'</span><br /> },<br /> {<br /> <span class="hljs-attr">name</span>: <span class="hljs-string">'age'</span>,<br /> <span class="hljs-attr">label</span>: <span class="hljs-string">'Age'</span>,<br /> <span class="hljs-attr">calculator</span>: <span class="hljs-function">(<span class="hljs-params">record</span>) =></span> {<br /> <span class="hljs-comment">// record.birthday is a string in the format "YYYY-MM-DD"</span><br /> <span class="hljs-keyword">const</span> today = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>();<br /> <span class="hljs-keyword">const</span> birthDate = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>(record.birthday);<br /> <span class="hljs-keyword">let</span> age = today.getFullYear() - birthDate.getFullYear();<br /> <span class="hljs-keyword">const</span> monthDifference = today.getMonth() - birthDate.getMonth();<br /> <span class="hljs-keyword">if</span> (monthDifference < <span class="hljs-number">0</span> || (monthDifference === <span class="hljs-number">0</span> && today.getDate() < birthDate.getDate())) {<br /> age--;<br /> }<br /> <span class="hljs-keyword">return</span> age;<br /> }<br /> },<br /> {<br /> <span class="hljs-attr">name</span>: <span class="hljs-string">'gender'</span>,<br /> <span class="hljs-attr">label</span>: <span class="hljs-string">'Gender'</span>,<br /> <span class="hljs-attr">formatter</span>: <span class="hljs-function">(<span class="hljs-params">v</span>) =></span> v===<span class="hljs-string">'m'</span>?<span class="hljs-string">'Male'</span>:<span class="hljs-string">'Female'</span> <span class="hljs-comment">// original value is "m" or "f"</span><br /> }<br /> ]<br /> });<br /></span><span class="hljs-tag"></<span class="hljs-name">script</span>></span></code></pre>
|
|
114
|
-
<k-table id="customFieldsExample"></k-table>
|
|
115
|
-
<script type="module">
|
|
116
|
-
document.getElementById('customFieldsExample').setData({
|
|
117
|
-
records: contacts.slice(0,10),
|
|
118
|
-
fields: [
|
|
119
|
-
{
|
|
120
|
-
name: "name",
|
|
121
|
-
label: "Name"
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
name: 'phoneNumber',
|
|
125
|
-
label: 'Phone Number'
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
name: 'email',
|
|
129
|
-
label: 'Email Address'
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
name: 'birthday',
|
|
133
|
-
label: 'Birthday'
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
name: 'age',
|
|
137
|
-
label: 'Age',
|
|
138
|
-
calculator: (record) => {
|
|
139
|
-
// record.birthday is a string in the format "YYYY-MM-DD"
|
|
140
|
-
const today = new Date();
|
|
141
|
-
const birthDate = new Date(record.birthday);
|
|
142
|
-
let age = today.getFullYear() - birthDate.getFullYear();
|
|
143
|
-
const monthDifference = today.getMonth() - birthDate.getMonth();
|
|
144
|
-
if (monthDifference < 0 || (monthDifference === 0 && today.getDate() < birthDate.getDate())) {
|
|
145
|
-
age--;
|
|
146
|
-
}
|
|
147
|
-
return age;
|
|
148
|
-
}
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
name: 'gender',
|
|
152
|
-
label: 'Gender',
|
|
153
|
-
formatter: (v) => v==='m'?'Male':'Female' // original value is "m" or "f"
|
|
154
|
-
}
|
|
155
|
-
]
|
|
156
|
-
});
|
|
157
|
-
</script>
|
|
158
|
-
|
|
159
|
-
<h3 id="topBottomControls"><a href="#topBottomControls" class="no-link">Top and Bottom Controls</a></h3>
|
|
160
|
-
<p>The table component can display controls at the top and bottom of the table. These controls can be used for pagination, adding new records, or any other actions. Each control is defined by an icon name, a callback function, and optionally an HTML string or a render function.</p>
|
|
161
|
-
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">k-table</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"topBottomControlsExample"</span>></span><span class="hljs-tag"></<span class="hljs-name">k-table</span>></span><br /><span class="hljs-tag"><<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>></span><span class="javascript"><br /> <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'topBottomControlsExample'</span>).setData({<br /> records: contacts.slice(<span class="hljs-number">10</span>, <span class="hljs-number">20</span>),<br /> controls: {<br /> <span class="hljs-attr">top</span>: [<br /> {<br /> <span class="hljs-attr">icon</span>: <span class="hljs-string">'add'</span>,<br /> <span class="hljs-attr">action</span>: <span class="hljs-function">(<span class="hljs-params">table</span>) =></span> table.addRecord(generateContact())<br /> }<br /> ],<br /> <span class="hljs-attr">bottom</span>: [<br /> {<br /> <span class="hljs-attr">icon</span>: <span class="hljs-string">'refresh'</span>,<br /> <span class="hljs-attr">action</span>: <span class="hljs-function">(<span class="hljs-params">table</span>) =></span> {<br /> contacts = contacts.sort(<span class="hljs-function"><span class="hljs-params">()</span> =></span> <span class="hljs-built_in">Math</span>.random() - <span class="hljs-number">0.5</span>);<br /> table.setRecords(contacts.slice(<span class="hljs-number">0</span>, <span class="hljs-number">10</span>));<br /> }<br /> }<br /> ]<br /> }<br /> });<br /></span><span class="hljs-tag"></<span class="hljs-name">script</span>></span></code></pre>
|
|
162
|
-
<k-table id="topBottomControlsExample"></k-table>
|
|
163
|
-
<script type="module">
|
|
164
|
-
document.getElementById('topBottomControlsExample').setData({
|
|
165
|
-
records: contacts.slice(10, 20),
|
|
166
|
-
controls: {
|
|
167
|
-
top: [
|
|
168
|
-
{
|
|
169
|
-
icon: 'add',
|
|
170
|
-
action: (table) => table.addRecord(generateContact())
|
|
171
|
-
}
|
|
172
|
-
],
|
|
173
|
-
bottom: [
|
|
174
|
-
{
|
|
175
|
-
icon: 'refresh',
|
|
176
|
-
action: (table) => {
|
|
177
|
-
contacts = contacts.sort(() => Math.random() - 0.5);
|
|
178
|
-
table.setRecords(contacts.slice(0, 10));
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
]
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
</script>
|
|
185
|
-
|
|
186
|
-
<h3 id="rowControls"><a href="#rowControls" class="no-link">Row Controls</a></h3>
|
|
187
|
-
<p>The table component can display controls before or after each row. Each control is defined by an icon name, a callback function, and optionally an HTML string or a render function.</p>
|
|
188
|
-
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">k-table</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"rowControlsExample"</span>></span><span class="hljs-tag"></<span class="hljs-name">k-table</span>></span><br /><span class="hljs-tag"><<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>></span><span class="javascript"><br /> <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'rowControlsExample'</span>).setData({<br /> records: contacts.slice(20, 25),<br /> controls: {<br /> <span class="hljs-attr">before</span>: [<br /> {<br /> <span class="hljs-attr">html</span>: <span class="hljs-string">'<span>Custom HTML</span> '</span><br /> },<br /> {<br /> <span class="hljs-attr">render</span>: <span class="hljs-function">(<span class="hljs-params">table, record</span>) =></span> {<br /> <span class="hljs-keyword">return</span> <span class="hljs-string">`<button onclick="alert('<span class="hljs-subst">${record.name}</span>')">Alert</button>`</span>;<br /> }<br /> }<br /> ],<br /> <span class="hljs-attr">after</span>: [<br /> {<br /> <span class="hljs-attr">icon</span>: <span class="hljs-string">'edit'</span>,<br /> <span class="hljs-attr">action</span>: <span class="hljs-function">(<span class="hljs-params">table, record, index</span>) =></span> {<br /> <span class="hljs-keyword">const</span> newName = prompt(<span class="hljs-string">"Enter a new name:"</span>, record.name);<br /> <span class="hljs-keyword">if</span> (newName) {<br /> record.name = newName;<br /> table.updateRecord(index, record);<br /> }<br /> }<br /> },<br /> {<br /> <span class="hljs-attr">icon</span>: <span class="hljs-string">'delete'</span>,<br /> <span class="hljs-attr">action</span>: <span class="hljs-function">(<span class="hljs-params">table, record, index</span>) =></span> {<br /> table.deleteRecord(index);<br /> }<br /> }<br /> ]<br /> }<br /> });<br /></span><span class="hljs-tag"></<span class="hljs-name">script</span>></span></code></pre>
|
|
189
|
-
<k-table id="rowControlsExample"></k-table>
|
|
190
|
-
<script type="module">
|
|
191
|
-
document.getElementById('rowControlsExample').setData({
|
|
192
|
-
records: contacts.slice(20, 25),
|
|
193
|
-
controls: {
|
|
194
|
-
before: [
|
|
195
|
-
{
|
|
196
|
-
html: '<span>Custom HTML</span> '
|
|
197
|
-
},
|
|
198
|
-
{
|
|
199
|
-
render: (table, record) => {
|
|
200
|
-
return `<button onclick="alert('${record.name}')">Alert</button>`;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
],
|
|
204
|
-
after: [
|
|
205
|
-
{
|
|
206
|
-
icon: 'edit',
|
|
207
|
-
action: (table, record, index) => {
|
|
208
|
-
const newName = prompt("Enter a new name:", record.name);
|
|
209
|
-
if (newName) {
|
|
210
|
-
record.name = newName;
|
|
211
|
-
table.updateRecord(index, record);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
},
|
|
215
|
-
{
|
|
216
|
-
icon: 'delete',
|
|
217
|
-
action: (table, record, index) => {
|
|
218
|
-
table.deleteRecord(index);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
]
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
</script>
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
<h3 id="pagination"><a href="#pagination" class="no-link">Pagination</a></h3>
|
|
228
|
-
<p>The table component supports pagination. You can set the page size and navigate through pages using the provided methods.</p>
|
|
229
|
-
<p>There are some predefined controls that you can use directly from <code>Table.controls</code>. These controls include:</p>
|
|
122
|
+
<h3>Examples</h3>
|
|
230
123
|
<ul>
|
|
231
|
-
<li><
|
|
232
|
-
<li><
|
|
233
|
-
<li><
|
|
234
|
-
<li><
|
|
235
|
-
<li><
|
|
124
|
+
<li><a href="tableCustomFields.html">Custom Fields Example</a></li>
|
|
125
|
+
<li><a href="tableControls.html">Top and Bottom Controls</a></li>
|
|
126
|
+
<li><a href="tableRowControls.html">Row Controls</a></li>
|
|
127
|
+
<li><a href="tablePagination.html">Pagination</a></li>
|
|
128
|
+
<li><a href="tableRecordSelection.html">Record Selection</a></li>
|
|
129
|
+
<li><a href="tableRecordEditing.html">Record Editing</a></li>
|
|
130
|
+
<li><a href="tableRecordHiding.html">Record Hiding</a></li>
|
|
131
|
+
<li><a href="tableRecordFiltering.html">Record Filtering</a></li>
|
|
236
132
|
</ul>
|
|
237
|
-
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">k-table</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"paginationExample"</span>></span><span class="hljs-tag"></<span class="hljs-name">k-table</span>></span><br /><span class="hljs-tag"><<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>></span><span class="javascript"><br /> <span class="hljs-keyword">import</span> Table <span class="hljs-keyword">from</span> <span class="hljs-string">'../kempo/components/Table.js'</span>;<br /> <span class="hljs-keyword">const</span> $paginationExample = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'paginationExample'</span>);<br /> $paginationExample.setData({<br /> <span class="hljs-attr">records</span>: contacts,<br /> <span class="hljs-attr">controls</span>: {<br /> <span class="hljs-attr">bottom</span>: [<br /> Table.controls.prevPage,<br /> Table.controls.nextPage,<br /> Table.controls.pageSelect,<br /> Table.controls.spacer,<br /> Table.controls.pageSize<br /> ]<br /> },<br /> <span class="hljs-attr">pageSize</span>: <span class="hljs-number">10</span>,<br /> <span class="hljs-attr">pageSizeOptions</span>: [<span class="hljs-number">5</span>, <span class="hljs-number">10</span>, <span class="hljs-number">20</span>]<br /> });<br /></span><span class="hljs-tag"></<span class="hljs-name">script</span>></span></code></pre>
|
|
238
|
-
<k-table id="paginationExample"></k-table>
|
|
239
|
-
<script type="module">
|
|
240
|
-
import Table from '../kempo/components/Table.js';
|
|
241
|
-
const $paginationExample = document.getElementById('paginationExample');
|
|
242
|
-
$paginationExample.setData({
|
|
243
|
-
records: contacts,
|
|
244
|
-
controls: {
|
|
245
|
-
bottom: [
|
|
246
|
-
Table.controls.prevPage,
|
|
247
|
-
Table.controls.nextPage,
|
|
248
|
-
Table.controls.pageSelect,
|
|
249
|
-
Table.controls.spacer,
|
|
250
|
-
Table.controls.pageSize
|
|
251
|
-
]
|
|
252
|
-
},
|
|
253
|
-
pageSize: 10,
|
|
254
|
-
pageSizeOptions: [5, 10, 20]
|
|
255
|
-
});
|
|
256
|
-
</script>
|
|
257
133
|
|
|
258
|
-
<
|
|
259
|
-
<
|
|
260
|
-
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">k-table</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"fetchRecordsExample"</span>></span><span class="hljs-tag"></<span class="hljs-name">k-table</span>></span><br /><span class="hljs-tag"><<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>></span><span class="javascript"><br /> <span class="hljs-keyword">import</span> Table <span class="hljs-keyword">from</span> <span class="hljs-string">'../kempo/components/Table.js'</span>;<br /><br /> <span class="hljs-keyword">const</span> $fetchRecordsExample = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'fetchRecordsExample'</span>);<br /> <span class="hljs-keyword">const</span> totalRecords = <span class="hljs-number">100</span>;<br /> $fetchRecordsExample.setData({<br /> <span class="hljs-attr">pageSize</span>: <span class="hljs-number">10</span>,<br /> <span class="hljs-attr">records</span>: contacts.slice(<span class="hljs-number">0</span>, <span class="hljs-number">10</span>),<br /> <span class="hljs-attr">controls</span>: {<br /> <span class="hljs-attr">bottom</span>: [<br /> Table.controls.prevPage,<br /> Table.controls.nextPage,<br /> Table.controls.pageSelect,<br /> Table.controls.spacer,<br /> Table.controls.pageSize<br /> ]<br /> }<br /> });<br /> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">mockFetchRecords</span>(<span class="hljs-params">start, count</span>) </span>{<br /> <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function">(<span class="hljs-params">resolve</span>) =></span> {<br /> setTimeout(<span class="hljs-function"><span class="hljs-params">()</span> =></span> {<br /> resolve(contacts.slice(start, start + count));<br /> }, <span class="hljs-number">1000</span>);<br /> });<br /> }<br /> $fetchRecordsExample.setupFetchRecords(totalRecords, mockFetchRecords);<br /></span><span class="hljs-tag"></<span class="hljs-name">script</span>></span></code></pre>
|
|
261
|
-
<k-table id="fetchRecordsExample"></k-table>
|
|
262
|
-
<script type="module">
|
|
263
|
-
import Table from '../kempo/components/Table.js';
|
|
264
|
-
|
|
265
|
-
const $fetchRecordsExample = document.getElementById('fetchRecordsExample');
|
|
266
|
-
const totalRecords = 100;
|
|
267
|
-
$fetchRecordsExample.setData({
|
|
268
|
-
pageSize: 10,
|
|
269
|
-
records: contacts.slice(0, 10),
|
|
270
|
-
controls: {
|
|
271
|
-
bottom: [
|
|
272
|
-
Table.controls.prevPage,
|
|
273
|
-
Table.controls.nextPage,
|
|
274
|
-
Table.controls.pageSelect,
|
|
275
|
-
Table.controls.spacer,
|
|
276
|
-
Table.controls.pageSize
|
|
277
|
-
]
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
function mockFetchRecords(start, count) {
|
|
281
|
-
return new Promise((resolve) => {
|
|
282
|
-
setTimeout(() => {
|
|
283
|
-
resolve(contacts.slice(start, start + count));
|
|
284
|
-
}, 1000);
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
$fetchRecordsExample.setupFetchRecords(totalRecords, mockFetchRecords);
|
|
288
|
-
</script>
|
|
134
|
+
<br />
|
|
135
|
+
<hr class="my" />
|
|
289
136
|
|
|
290
137
|
<h2>JavaScript Reference</h2>
|
|
291
138
|
<h3 id="constructor"><a href="#constructor" class="no-link">Constructor</a></h3>
|
|
@@ -337,6 +184,10 @@
|
|
|
337
184
|
<li><code>controls</code>: An object containing optional arrays of controls to be displayed before and/or after each row. Each control is defined by an icon name, a callback function, and optionally an HTML string or a render function. The <code>controls</code> object can contain the optional <code>before</code> and <code>after</code> properties, which are arrays of objects containing the <code>icon</code> (string), <code>action</code> (function), <code>html</code> (string), and <code>render</code> (function). If <code>html</code> is present, it overrides the icon and is rendered in its place. If <code>render</code> is present, it is used to render the control.</li>
|
|
338
185
|
<li><code>pageSize</code>: The number of records to display per page.</li>
|
|
339
186
|
<li><code>pageSizeOptions</code>: An array of numbers representing the available page size options.</li>
|
|
187
|
+
<li><code>currentPage</code>: The current page to display.</li>
|
|
188
|
+
<li><code>enableSelection</code>: A boolean to enable or disable record selection.</li>
|
|
189
|
+
<li><code>enablePages</code>: A boolean to enable or disable pagination.</li>
|
|
190
|
+
<li><code>filters</code>: An array of filter objects to apply to the records.</li>
|
|
340
191
|
</ul>
|
|
341
192
|
|
|
342
193
|
<h5><code>renderFields()<i>: undefined</i></code></h5>
|
|
@@ -348,11 +199,11 @@
|
|
|
348
199
|
<h5><code>addRecord(<i>object</i> record)<i>: undefined</i></code></h5>
|
|
349
200
|
<p>Adds a new record to the table.</p>
|
|
350
201
|
|
|
351
|
-
<h5><code>updateRecord(<i>
|
|
352
|
-
<p>Updates an existing record
|
|
202
|
+
<h5><code>updateRecord(<i>object</i> record, <i>object</i> newData)<i>: undefined</i></code></h5>
|
|
203
|
+
<p>Updates an existing record with new data.</p>
|
|
353
204
|
|
|
354
|
-
<h5><code>deleteRecord(<i>
|
|
355
|
-
<p>Deletes a record
|
|
205
|
+
<h5><code>deleteRecord(<i>object</i> record)<i>: undefined</i></code></h5>
|
|
206
|
+
<p>Deletes a record from the table.</p>
|
|
356
207
|
|
|
357
208
|
<h5><code>setRecords(<i>Array</i> records)<i>: undefined</i></code></h5>
|
|
358
209
|
<p>Sets the records for the table and re-renders the rows.</p>
|
|
@@ -360,13 +211,25 @@
|
|
|
360
211
|
<h5><code>setPageSize(<i>number</i> pageSize)<i>: undefined</i></code></h5>
|
|
361
212
|
<p>Sets the number of records to display per page.</p>
|
|
362
213
|
|
|
363
|
-
<h5><code>
|
|
364
|
-
<p>
|
|
214
|
+
<h5><code>setPage(<i>number</i> page)<i>: undefined</i></code></h5>
|
|
215
|
+
<p>Sets the current page to display.</p>
|
|
216
|
+
|
|
217
|
+
<h5><code>nextPage()<i>: undefined</i></code></h5>
|
|
218
|
+
<p>Moves to the next page.</p>
|
|
219
|
+
|
|
220
|
+
<h5><code>prevPage()<i>: undefined</i></h5>
|
|
221
|
+
<p>Moves to the previous page.</p>
|
|
222
|
+
|
|
223
|
+
<h5><code>getCurrentPage()<i>: number</i></code></h5>
|
|
224
|
+
<p>Returns the current page number.</p>
|
|
225
|
+
|
|
226
|
+
<h5><code>getTotalPages()<i>: number</i></code></h5>
|
|
227
|
+
<p>Returns the total number of pages.</p>
|
|
365
228
|
|
|
366
229
|
<h5><code>getSelectedRecords()<i>: Array</i></code></h5>
|
|
367
230
|
<p>Returns an array of the currently selected records.</p>
|
|
368
231
|
|
|
369
|
-
<h5><code>
|
|
232
|
+
<h5><code>deleteSelected()<i>: undefined</i></code></h5>
|
|
370
233
|
<p>Deletes all currently selected records from the table.</p>
|
|
371
234
|
|
|
372
235
|
<h5><code>selectAllOnPage()<i>: undefined</i></code></h5>
|
|
@@ -375,9 +238,47 @@
|
|
|
375
238
|
<h5><code>deselectAllOnPage()<i>: undefined</i></code></h5>
|
|
376
239
|
<p>Deselects all the records on the current page.</p>
|
|
377
240
|
|
|
378
|
-
<h5><code>allOnPageSelected()<i>:
|
|
241
|
+
<h5><code>allOnPageSelected()<i>: boolean</i></code></h5>
|
|
379
242
|
<p>Returns <code>true</code> if all the records on the current page are selected, and <code>false</code> if they are not.</p>
|
|
380
|
-
|
|
243
|
+
|
|
244
|
+
<h5><code>editRecord(<i>object</i> record)<i>: undefined</i></code></h5>
|
|
245
|
+
<p>Enables editing mode for a record.</p>
|
|
246
|
+
|
|
247
|
+
<h5><code>saveEditedRecord(<i>object</i> record)<i>: undefined</i></code></h5>
|
|
248
|
+
<p>Saves the changes made to an edited record.</p>
|
|
249
|
+
|
|
250
|
+
<h5><code>cancelEditedRecord(<i>object</i> record)<i>: undefined</i></code></h5>
|
|
251
|
+
<p>Cancels the editing mode for a record.</p>
|
|
252
|
+
|
|
253
|
+
<h5><code>recordIsEditing(<i>object</i> record)<i>: boolean</i></code></h5>
|
|
254
|
+
<p>Returns <code>true</code> if the record is in editing mode, and <code>false</code> if it is not.</p>
|
|
255
|
+
|
|
256
|
+
<h5><code>hideRecord(<i>object</i> record)<i>: undefined</i></code></h5>
|
|
257
|
+
<p>Hides a record from the table.</p>
|
|
258
|
+
|
|
259
|
+
<h5><code>showRecord(<i>object</i> record)<i>: undefined</i></code></h5>
|
|
260
|
+
<p>Shows a hidden record in the table.</p>
|
|
261
|
+
|
|
262
|
+
<h5><code>showAllRecords()<i>: undefined</i></code></h5>
|
|
263
|
+
<p>Shows all hidden records in the table.</p>
|
|
264
|
+
|
|
265
|
+
<h5><code>addFilter(<i>string</i> field, <i>string</i> condition, <i>any</i> value)<i>: undefined</i></h5>
|
|
266
|
+
<p>Adds a filter to the table.</p>
|
|
267
|
+
|
|
268
|
+
<h5><code>removeFilter(<i>string</i> field, <i>string</i> condition, <i>any</i> value)<i>: undefined</i></h5>
|
|
269
|
+
<p>Removes a filter from the table.</p>
|
|
270
|
+
|
|
271
|
+
<h5><code>getDisplayedRecords()<i>: Array</i></code></h5>
|
|
272
|
+
<p>Returns an array of the records currently displayed in the table.</p>
|
|
273
|
+
|
|
274
|
+
<h5><code>getHiddenRecords()<i>: Array</i></code></h5>
|
|
275
|
+
<p>Returns an array of the hidden records in the table.</p>
|
|
276
|
+
|
|
277
|
+
<h5><code>setupFetchRecords(<i>number</i> totalRecords, <i>function</i> callback)<i>: undefined</i></h5>
|
|
278
|
+
<p>Sets up the table to fetch records dynamically.</p>
|
|
279
|
+
|
|
280
|
+
<h5><code>sortBy(<i>string</i> field, <i>boolean</i> asc)<i>: undefined</i></h5>
|
|
281
|
+
<p>Sorts the records by the specified field in ascending or descending order.</p>
|
|
381
282
|
|
|
382
283
|
</main>
|
|
383
284
|
<div style="height: 33.333vh"></div>
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>Top and Bottom Controls - Table - Kempo Docs</title>
|
|
7
|
+
<link rel="stylesheet" href="../kempo/kempo-vars.css" />
|
|
8
|
+
<link rel="stylesheet" href="../kempo/kempo-styles.css" />
|
|
9
|
+
<link rel="stylesheet" href="../kempo/kempo-hljs.css" />
|
|
10
|
+
<script type="module" src="../kempo/components/Table.js"></script>
|
|
11
|
+
<script type="module">
|
|
12
|
+
import Icon from '../kempo/components/Icon.js';
|
|
13
|
+
import Search from '../kempo/components/Search.js';
|
|
14
|
+
Icon.pathToIcons = ['../icons'];
|
|
15
|
+
Search.searchDataUrl = '../search.json';
|
|
16
|
+
</script>
|
|
17
|
+
<script>
|
|
18
|
+
window.contacts = [];
|
|
19
|
+
function generateContact(){
|
|
20
|
+
const maleNames = [
|
|
21
|
+
"Liam", "Noah", "Oliver", "Elijah", "William", "James", "Benjamin",
|
|
22
|
+
"Lucas", "Henry", "Alexander", "Mason", "Michael", "Ethan", "Daniel",
|
|
23
|
+
"Jacob", "Logan", "Jackson", "Levi", "Sebastian", "Mateo", "Jack",
|
|
24
|
+
"Owen", "Theodore", "Aiden", "Samuel", "Joseph", "John", "David",
|
|
25
|
+
"Wyatt", "Matthew"
|
|
26
|
+
];
|
|
27
|
+
const femaleNames = [
|
|
28
|
+
"Olivia", "Emma", "Ava", "Sophia", "Isabella", "Mia", "Amelia",
|
|
29
|
+
"Harper", "Evelyn", "Abigail", "Emily", "Ella", "Elizabeth",
|
|
30
|
+
"Camila", "Luna", "Sofia", "Avery", "Mila", "Aria", "Scarlett",
|
|
31
|
+
"Penelope", "Layla", "Chloe", "Victoria", "Madison", "Eleanor",
|
|
32
|
+
"Grace", "Nora", "Riley", "Zoey"
|
|
33
|
+
];
|
|
34
|
+
const lastNames = [
|
|
35
|
+
"Smith", "Johnson", "Williams", "Brown", "Jones", "Garcia", "Miller",
|
|
36
|
+
"Davis", "Rodriguez", "Martinez", "Hernandez", "Lopez", "Gonzalez",
|
|
37
|
+
"Wilson", "Anderson", "Thomas", "Taylor", "Moore", "Jackson", "Martin",
|
|
38
|
+
"Lee", "Perez", "Thompson", "White", "Harris", "Sanchez", "Clark",
|
|
39
|
+
"Ramirez", "Lewis", "Robinson"
|
|
40
|
+
];
|
|
41
|
+
const gender = Math.random() > 0.5 ? 'm' : 'f';
|
|
42
|
+
const firstName = gender === 'm' ? maleNames[Math.floor(Math.random() * maleNames.length)] : femaleNames[Math.floor(Math.random() * femaleNames.length)];
|
|
43
|
+
const lastName = lastNames[Math.floor(Math.random() * lastNames.length)];
|
|
44
|
+
const name = `${firstName} ${lastName}`;
|
|
45
|
+
const email = `${firstName.toLowerCase()}.${lastName.toLowerCase()}@mailserver.com`;
|
|
46
|
+
const birthday = `${Math.floor(Math.random() * 100) + 1920}-${String(Math.floor(Math.random() * 12) + 1).padStart(2, '0')}-${String(Math.floor(Math.random() * 28) + 1).padStart(2, '0')}`;
|
|
47
|
+
const phoneNumber = `(${Math.floor(Math.random() * 900) + 100}) ${Math.floor(Math.random() * 900) + 100}-${Math.floor(Math.random() * 9000) + 1000}`;
|
|
48
|
+
return { name, email, birthday, phoneNumber, gender };
|
|
49
|
+
}
|
|
50
|
+
for (let i = 0; i < 100; i++) {
|
|
51
|
+
contacts.push(generateContact());
|
|
52
|
+
};
|
|
53
|
+
</script>
|
|
54
|
+
</head>
|
|
55
|
+
<body>
|
|
56
|
+
<k-import src="../nav-1.inc.html"></k-import>
|
|
57
|
+
<h1 class="ta-center">Table - Top and Bottom Controls</h1>
|
|
58
|
+
<main>
|
|
59
|
+
|
|
60
|
+
<a href="./table.html"><h5>Back to Table Component Documentation</h5></a>
|
|
61
|
+
|
|
62
|
+
<p>The table component can display controls at the top and bottom of the table. These controls can be used for pagination, adding new records, or any other actions. Each control is defined by an icon name, a callback function, and optionally an HTML string or a render function.</p>
|
|
63
|
+
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">k-table</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"topBottomControlsExample"</span>></span><span class="hljs-tag"></<span class="hljs-name">k-table</span>></span><br /><span class="hljs-tag"><<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>></span><span class="javascript"><br /> <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'topBottomControlsExample'</span>).setData({<br /> <span class="hljs-attr">records</span>: contacts.slice(<span class="hljs-number">0</span>, <span class="hljs-number">10</span>),<br /> <span class="hljs-attr">controls</span>: {<br /> <span class="hljs-attr">top</span>: [<br /> {<br /> <span class="hljs-attr">icon</span>: <span class="hljs-string">'add'</span>,<br /> <span class="hljs-attr">action</span>: <span class="hljs-function">(<span class="hljs-params">table</span>) =></span> table.addRecord(generateContact())<br /> }<br /> ],<br /> <span class="hljs-attr">bottom</span>: [<br /> {<br /> <span class="hljs-attr">icon</span>: <span class="hljs-string">'refresh'</span>,<br /> <span class="hljs-attr">action</span>: <span class="hljs-function">(<span class="hljs-params">table</span>) =></span> {<br /> contacts = contacts.sort(<span class="hljs-function"><span class="hljs-params">()</span> =></span> <span class="hljs-built_in">Math</span>.random() - <span class="hljs-number">0.5</span>);<br /> table.setRecords(contacts.slice(<span class="hljs-number">0</span>, <span class="hljs-number">10</span>));<br /> }<br /> }<br /> ]<br /> }<br /> });<br /></span><span class="hljs-tag"></<span class="hljs-name">script</span>></span></code></pre>
|
|
64
|
+
<k-table id="topBottomControlsExample"></k-table>
|
|
65
|
+
<script type="module">
|
|
66
|
+
document.getElementById('topBottomControlsExample').setData({
|
|
67
|
+
records: contacts.slice(0, 10),
|
|
68
|
+
controls: {
|
|
69
|
+
top: [
|
|
70
|
+
{
|
|
71
|
+
icon: 'add',
|
|
72
|
+
action: (table) => table.addRecord(generateContact())
|
|
73
|
+
}
|
|
74
|
+
],
|
|
75
|
+
bottom: [
|
|
76
|
+
{
|
|
77
|
+
icon: 'refresh',
|
|
78
|
+
action: (table) => {
|
|
79
|
+
contacts = contacts.sort(() => Math.random() - 0.5);
|
|
80
|
+
table.setRecords(contacts.slice(0, 10));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
</script>
|
|
87
|
+
</main>
|
|
88
|
+
<div style="height: 33.333vh"></div>
|
|
89
|
+
<script type="module" src="../kempo/components/Import.js"></script>
|
|
90
|
+
</body>
|
|
91
|
+
</html>
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>Custom Fields - Table - Kempo Docs</title>
|
|
7
|
+
<link rel="stylesheet" href="../kempo/kempo-vars.css" />
|
|
8
|
+
<link rel="stylesheet" href="../kempo/kempo-styles.css" />
|
|
9
|
+
<link rel="stylesheet" href="../kempo/kempo-hljs.css" />
|
|
10
|
+
<script type="module" src="../kempo/components/Table.js"></script>
|
|
11
|
+
<script type="module">
|
|
12
|
+
import Icon from '../kempo/components/Icon.js';
|
|
13
|
+
import Search from '../kempo/components/Search.js';
|
|
14
|
+
Icon.pathToIcons = ['../icons'];
|
|
15
|
+
Search.searchDataUrl = '../search.json';
|
|
16
|
+
</script>
|
|
17
|
+
<script>
|
|
18
|
+
window.contacts = [];
|
|
19
|
+
function generateContact(){
|
|
20
|
+
const maleNames = [
|
|
21
|
+
"Liam", "Noah", "Oliver", "Elijah", "William", "James", "Benjamin",
|
|
22
|
+
"Lucas", "Henry", "Alexander", "Mason", "Michael", "Ethan", "Daniel",
|
|
23
|
+
"Jacob", "Logan", "Jackson", "Levi", "Sebastian", "Mateo", "Jack",
|
|
24
|
+
"Owen", "Theodore", "Aiden", "Samuel", "Joseph", "John", "David",
|
|
25
|
+
"Wyatt", "Matthew"
|
|
26
|
+
];
|
|
27
|
+
const femaleNames = [
|
|
28
|
+
"Olivia", "Emma", "Ava", "Sophia", "Isabella", "Mia", "Amelia",
|
|
29
|
+
"Harper", "Evelyn", "Abigail", "Emily", "Ella", "Elizabeth",
|
|
30
|
+
"Camila", "Luna", "Sofia", "Avery", "Mila", "Aria", "Scarlett",
|
|
31
|
+
"Penelope", "Layla", "Chloe", "Victoria", "Madison", "Eleanor",
|
|
32
|
+
"Grace", "Nora", "Riley", "Zoey"
|
|
33
|
+
];
|
|
34
|
+
const lastNames = [
|
|
35
|
+
"Smith", "Johnson", "Williams", "Brown", "Jones", "Garcia", "Miller",
|
|
36
|
+
"Davis", "Rodriguez", "Martinez", "Hernandez", "Lopez", "Gonzalez",
|
|
37
|
+
"Wilson", "Anderson", "Thomas", "Taylor", "Moore", "Jackson", "Martin",
|
|
38
|
+
"Lee", "Perez", "Thompson", "White", "Harris", "Sanchez", "Clark",
|
|
39
|
+
"Ramirez", "Lewis", "Robinson"
|
|
40
|
+
];
|
|
41
|
+
const gender = Math.random() > 0.5 ? 'm' : 'f';
|
|
42
|
+
const firstName = gender === 'm' ? maleNames[Math.floor(Math.random() * maleNames.length)] : femaleNames[Math.floor(Math.random() * femaleNames.length)];
|
|
43
|
+
const lastName = lastNames[Math.floor(Math.random() * lastNames.length)];
|
|
44
|
+
const name = `${firstName} ${lastName}`;
|
|
45
|
+
const email = `${firstName.toLowerCase()}.${lastName.toLowerCase()}@mailserver.com`;
|
|
46
|
+
const birthday = `${Math.floor(Math.random() * 100) + 1920}-${String(Math.floor(Math.random() * 12) + 1).padStart(2, '0')}-${String(Math.floor(Math.random() * 28) + 1).padStart(2, '0')}`;
|
|
47
|
+
const phoneNumber = `(${Math.floor(Math.random() * 900) + 100}) ${Math.floor(Math.random() * 900) + 100}-${Math.floor(Math.random() * 9000) + 1000}`;
|
|
48
|
+
return { name, email, birthday, phoneNumber, gender };
|
|
49
|
+
}
|
|
50
|
+
for (let i = 0; i < 10; i++) {
|
|
51
|
+
contacts.push(generateContact());
|
|
52
|
+
};
|
|
53
|
+
</script>
|
|
54
|
+
</head>
|
|
55
|
+
<body>
|
|
56
|
+
<k-import src="../nav-1.inc.html"></k-import>
|
|
57
|
+
<h1 class="ta-center">Table - Custom Fields</h1>
|
|
58
|
+
<main>
|
|
59
|
+
|
|
60
|
+
<a href="./table.html"><h5>Back to Table Component Documentation</h5></a>
|
|
61
|
+
|
|
62
|
+
<p>Use the <code>fields</code> property of the options object in <code>setData</code> to define custom fields. This is useful for hiding fields, reordering fields, changing the labels, formatting the output, or creating a calculated field.</p>
|
|
63
|
+
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">k-table</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"customFieldsExample"</span>></span><span class="hljs-tag"></<span class="hljs-name">k-table</span>></span><br /><span class="hljs-tag"><<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>></span><span class="javascript"><br /> <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'customFieldsExample'</span>).setData({<br /> <span class="hljs-attr">records</span>: contacts,<br /> <span class="hljs-attr">fields</span>: [<br /> {<br /> <span class="hljs-attr">name</span>: <span class="hljs-string">"name"</span>,<br /> <span class="hljs-attr">label</span>: <span class="hljs-string">"Name"</span><br /> },<br /> {<br /> <span class="hljs-attr">name</span>: <span class="hljs-string">'phoneNumber'</span>,<br /> <span class="hljs-attr">label</span>: <span class="hljs-string">'Phone Number'</span><br /> },<br /> {<br /> <span class="hljs-attr">name</span>: <span class="hljs-string">'email'</span>,<br /> <span class="hljs-attr">label</span>: <span class="hljs-string">'Email Address'</span><br /> },<br /> {<br /> <span class="hljs-attr">name</span>: <span class="hljs-string">'birthday'</span>,<br /> <span class="hljs-attr">label</span>: <span class="hljs-string">'Birthday'</span><br /> },<br /> {<br /> <span class="hljs-attr">name</span>: <span class="hljs-string">'age'</span>,<br /> <span class="hljs-attr">label</span>: <span class="hljs-string">'Age'</span>,<br /> <span class="hljs-attr">calculator</span>: <span class="hljs-function">(<span class="hljs-params">record</span>) =></span> {<br /> <span class="hljs-comment">// record.birthday is a string in the format "YYYY-MM-DD"</span><br /> <span class="hljs-keyword">const</span> today = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>();<br /> <span class="hljs-keyword">const</span> birthDate = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>(record.birthday);<br /> <span class="hljs-keyword">let</span> age = today.getFullYear() - birthDate.getFullYear();<br /> <span class="hljs-keyword">const</span> monthDifference = today.getMonth() - birthDate.getMonth();<br /> <span class="hljs-keyword">if</span> (monthDifference < <span class="hljs-number">0</span> || (monthDifference === <span class="hljs-number">0</span> && today.getDate() < birthDate.getDate())) {<br /> age--;<br /> }<br /> <span class="hljs-keyword">return</span> age;<br /> }<br /> },<br /> {<br /> <span class="hljs-attr">name</span>: <span class="hljs-string">'gender'</span>,<br /> <span class="hljs-attr">label</span>: <span class="hljs-string">'Gender'</span>,<br /> <span class="hljs-attr">formatter</span>: <span class="hljs-function">(<span class="hljs-params">v</span>) =></span> v===<span class="hljs-string">'m'</span>?<span class="hljs-string">'Male'</span>:<span class="hljs-string">'Female'</span> <span class="hljs-comment">// original value is "m" or "f"</span><br /> }<br /> ]<br /> });<br /></span><span class="hljs-tag"></<span class="hljs-name">script</span>></span></code></pre>
|
|
64
|
+
<k-table id="customFieldsExample"></k-table>
|
|
65
|
+
<script type="module">
|
|
66
|
+
document.getElementById('customFieldsExample').setData({
|
|
67
|
+
records: contacts,
|
|
68
|
+
fields: [
|
|
69
|
+
{
|
|
70
|
+
name: "name",
|
|
71
|
+
label: "Name"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: 'phoneNumber',
|
|
75
|
+
label: 'Phone Number'
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: 'email',
|
|
79
|
+
label: 'Email Address'
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: 'birthday',
|
|
83
|
+
label: 'Birthday'
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
name: 'age',
|
|
87
|
+
label: 'Age',
|
|
88
|
+
calculator: (record) => {
|
|
89
|
+
// record.birthday is a string in the format "YYYY-MM-DD"
|
|
90
|
+
const today = new Date();
|
|
91
|
+
const birthDate = new Date(record.birthday);
|
|
92
|
+
let age = today.getFullYear() - birthDate.getFullYear();
|
|
93
|
+
const monthDifference = today.getMonth() - birthDate.getMonth();
|
|
94
|
+
if (monthDifference < 0 || (monthDifference === 0 && today.getDate() < birthDate.getDate())) {
|
|
95
|
+
age--;
|
|
96
|
+
}
|
|
97
|
+
return age;
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
name: 'gender',
|
|
102
|
+
label: 'Gender',
|
|
103
|
+
formatter: (v) => v==='m'?'Male':'Female' // original value is "m" or "f"
|
|
104
|
+
}
|
|
105
|
+
]
|
|
106
|
+
});
|
|
107
|
+
</script>
|
|
108
|
+
</main>
|
|
109
|
+
<div style="height: 33.333vh"></div>
|
|
110
|
+
<script type="module" src="../kempo/components/Import.js"></script>
|
|
111
|
+
</body>
|
|
112
|
+
</html>
|