kempo 2.9.4 → 2.10.1

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.
Files changed (116) hide show
  1. package/dist/components/Dialog.js +1 -1
  2. package/dist/components/Icon.js +1 -1
  3. package/dist/components/Search.js +1 -1
  4. package/dist/components/Sortable.js +1 -0
  5. package/dist/components/Table.js +1 -1
  6. package/dist/components/tableControls/DeleteRecord.js +1 -0
  7. package/dist/components/tableControls/DeleteSelected.js +1 -1
  8. package/dist/components/tableControls/Edit.js +1 -0
  9. package/dist/components/tableControls/ExportCSV.js +1 -0
  10. package/dist/components/tableControls/ExportJson.js +1 -0
  11. package/dist/components/tableControls/FieldSortHide.js +1 -0
  12. package/dist/components/tableControls/Filters.js +1 -0
  13. package/dist/components/tableControls/FirstPage.js +1 -0
  14. package/dist/components/tableControls/HiddenCount.js +1 -0
  15. package/dist/components/tableControls/Hide.js +1 -0
  16. package/dist/components/tableControls/LastPage.js +1 -0
  17. package/dist/components/tableControls/NextPage.js +1 -0
  18. package/dist/components/tableControls/PageSelect.js +1 -1
  19. package/dist/components/tableControls/PageSize.js +1 -1
  20. package/dist/components/tableControls/PrevPage.js +1 -0
  21. package/dist/components/tableControls/Search.js +1 -0
  22. package/dist/components/tableControls/SelectCount.js +1 -1
  23. package/dist/components/tableControls/ShowAll.js +1 -0
  24. package/dist/components/tableControls/ShowHideFields.js +1 -0
  25. package/dist/components/tableControls/TableControl.js +1 -0
  26. package/dist/index.js +1 -1
  27. package/dist/kempo-styles.css +1 -1
  28. package/dist/kempo-vars.css +1 -1
  29. package/docs/components/sortable.html +96 -0
  30. package/docs/components/table.html +108 -182
  31. package/docs/components/tableControls.html +77 -0
  32. package/docs/components/tableCustomFields.html +112 -0
  33. package/docs/components/tableFetchRecords.html +114 -0
  34. package/docs/components/tableFieldSortHide.html +75 -0
  35. package/docs/components/tablePagination.html +100 -0
  36. package/docs/components/tableRecordEditing.html +144 -0
  37. package/docs/components/tableRecordFiltering.html +75 -0
  38. package/docs/components/tableRecordHiding.html +80 -0
  39. package/docs/components/tableRecordSearching.html +75 -0
  40. package/docs/components/tableRecordSelection.html +75 -0
  41. package/docs/components/tableRowControls.html +78 -0
  42. package/docs/components/tableSorting.html +73 -0
  43. package/docs/icons/arrow-down.svg +1 -0
  44. package/docs/icons/arrow-up.svg +1 -0
  45. package/docs/icons/check.svg +1 -0
  46. package/docs/icons/drag-handle.svg +1 -0
  47. package/docs/icons/export-file.svg +1 -0
  48. package/docs/icons/first.svg +1 -0
  49. package/docs/icons/hide.svg +1 -0
  50. package/docs/icons/last.svg +1 -0
  51. package/docs/icons/show.svg +1 -0
  52. package/docs/icons/table-visibility.svg +1 -0
  53. package/docs/kempo/components/Dialog.js +1 -1
  54. package/docs/kempo/components/Icon.js +1 -1
  55. package/docs/kempo/components/Search.js +1 -1
  56. package/docs/kempo/components/Sortable.js +1 -0
  57. package/docs/kempo/components/Table.js +1 -1
  58. package/docs/kempo/components/tableControls/DeleteRecord.js +1 -0
  59. package/docs/kempo/components/tableControls/DeleteSelected.js +1 -1
  60. package/docs/kempo/components/tableControls/Edit.js +1 -0
  61. package/docs/kempo/components/tableControls/ExportCSV.js +1 -0
  62. package/docs/kempo/components/tableControls/ExportJson.js +1 -0
  63. package/docs/kempo/components/tableControls/FieldSortHide.js +1 -0
  64. package/docs/kempo/components/tableControls/Filters.js +1 -0
  65. package/docs/kempo/components/tableControls/FirstPage.js +1 -0
  66. package/docs/kempo/components/tableControls/HiddenCount.js +1 -0
  67. package/docs/kempo/components/tableControls/Hide.js +1 -0
  68. package/docs/kempo/components/tableControls/LastPage.js +1 -0
  69. package/docs/kempo/components/tableControls/NextPage.js +1 -0
  70. package/docs/kempo/components/tableControls/PageSelect.js +1 -1
  71. package/docs/kempo/components/tableControls/PageSize.js +1 -1
  72. package/docs/kempo/components/tableControls/PrevPage.js +1 -0
  73. package/docs/kempo/components/tableControls/Search.js +1 -0
  74. package/docs/kempo/components/tableControls/SelectCount.js +1 -1
  75. package/docs/kempo/components/tableControls/ShowAll.js +1 -0
  76. package/docs/kempo/components/tableControls/ShowHideFields.js +1 -0
  77. package/docs/kempo/components/tableControls/TableControl.js +1 -0
  78. package/docs/kempo/index.js +1 -1
  79. package/docs/kempo/kempo-styles.css +1 -1
  80. package/docs/kempo/kempo-vars.css +1 -1
  81. package/icons/arrow-down.svg +1 -0
  82. package/icons/arrow-up.svg +1 -0
  83. package/icons/check.svg +1 -0
  84. package/icons/drag-handle.svg +1 -0
  85. package/icons/export-file.svg +1 -0
  86. package/icons/first.svg +1 -0
  87. package/icons/hide.svg +1 -0
  88. package/icons/last.svg +1 -0
  89. package/icons/show.svg +1 -0
  90. package/icons/table-visibility.svg +1 -0
  91. package/package.json +1 -1
  92. package/src/components/Dialog.js +12 -4
  93. package/src/components/Icon.js +3 -1
  94. package/src/components/Sortable.js +169 -0
  95. package/src/components/Table.js +703 -247
  96. package/src/components/tableControls/DeleteRecord.js +43 -0
  97. package/src/components/tableControls/DeleteSelected.js +36 -24
  98. package/src/components/tableControls/Edit.js +84 -0
  99. package/src/components/tableControls/ExportCSV.js +91 -0
  100. package/src/components/tableControls/ExportJson.js +62 -0
  101. package/src/components/tableControls/FieldSortHide.js +77 -0
  102. package/src/components/tableControls/Filters.js +129 -0
  103. package/src/components/tableControls/FirstPage.js +69 -0
  104. package/src/components/tableControls/HiddenCount.js +37 -0
  105. package/src/components/tableControls/Hide.js +40 -0
  106. package/src/components/tableControls/LastPage.js +67 -0
  107. package/src/components/tableControls/NextPage.js +69 -0
  108. package/src/components/tableControls/PageSelect.js +55 -34
  109. package/src/components/tableControls/PageSize.js +31 -17
  110. package/src/components/tableControls/PrevPage.js +69 -0
  111. package/src/components/tableControls/Search.js +49 -0
  112. package/src/components/tableControls/SelectCount.js +5 -10
  113. package/src/components/tableControls/ShowAll.js +37 -0
  114. package/src/components/tableControls/TableControl.js +51 -0
  115. package/src/kempo-styles.css +7 -0
  116. package/src/kempo-vars.css +2 -0
@@ -4,7 +4,8 @@
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" /><link rel="stylesheet" href="../kempo/kempo-styles.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>
10
11
  <script type="module">
@@ -63,10 +64,18 @@
63
64
  <div class="m mt0 pl">
64
65
  <h6>Examples</h6>
65
66
  <a href="#basicUsage">Basic Usage</a><br />
66
- <a href="#customFields">Custom Fields</a><br />
67
- <a href="#topBottomControls">Top and Bottom Controls</a><br />
68
- <a href="#rowControls">Row Controls</a><br />
69
- <a href="#pagination">Pagination</a><br />
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 />
75
+ <a href="tableRecordSearching.html">Record Searching</a><br />
76
+ <a href="tableSorting.html">Sorting</a><br />
77
+ <a href="tableFieldSortHide.html">Field Sorting and Hiding</a><br />
78
+ <a href="tableFetchRecords.html">Fetching Records</a><br />
70
79
  <h6 class="mt">JavaScript Reference</h6>
71
80
  <a href="#constructor">Constructor</a><br />
72
81
  <a href="#requirements">Requirements</a><br />
@@ -114,175 +123,21 @@
114
123
  });
115
124
  </script>
116
125
 
117
- <h3 id="customFields"><a href="#customFields" class="no-link">Custom Fields</a></h3>
118
- <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>
119
- <pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">k-table</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"customFieldsExample"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">k-table</span>&gt;</span><br /><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>&gt;</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>) =&gt;</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 &lt; <span class="hljs-number">0</span> || (monthDifference === <span class="hljs-number">0</span> &amp;&amp; today.getDate() &lt; 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>) =&gt;</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">&lt;/<span class="hljs-name">script</span>&gt;</span></code></pre>
120
- <k-table id="customFieldsExample"></k-table>
121
- <script type="module">
122
- document.getElementById('customFieldsExample').setData({
123
- records: contacts.slice(0,10),
124
- fields: [
125
- {
126
- name: "name",
127
- label: "Name"
128
- },
129
- {
130
- name: 'phoneNumber',
131
- label: 'Phone Number'
132
- },
133
- {
134
- name: 'email',
135
- label: 'Email Address'
136
- },
137
- {
138
- name: 'birthday',
139
- label: 'Birthday'
140
- },
141
- {
142
- name: 'age',
143
- label: 'Age',
144
- calculator: (record) => {
145
- // record.birthday is a string in the format "YYYY-MM-DD"
146
- const today = new Date();
147
- const birthDate = new Date(record.birthday);
148
- let age = today.getFullYear() - birthDate.getFullYear();
149
- const monthDifference = today.getMonth() - birthDate.getMonth();
150
- if (monthDifference < 0 || (monthDifference === 0 && today.getDate() < birthDate.getDate())) {
151
- age--;
152
- }
153
- return age;
154
- }
155
- },
156
- {
157
- name: 'gender',
158
- label: 'Gender',
159
- formatter: (v) => v==='m'?'Male':'Female' // original value is "m" or "f"
160
- }
161
- ]
162
- });
163
- </script>
164
-
165
- <h3 id="topBottomControls"><a href="#topBottomControls" class="no-link">Top and Bottom Controls</a></h3>
166
- <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>
167
- <pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">k-table</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"topBottomControlsExample"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">k-table</span>&gt;</span><br /><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>&gt;</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>) =&gt;</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>) =&gt;</span> {<br /> contacts = contacts.sort(<span class="hljs-function"><span class="hljs-params">()</span> =&gt;</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">&lt;/<span class="hljs-name">script</span>&gt;</span></code></pre>
168
- <k-table id="topBottomControlsExample"></k-table>
169
- <script type="module">
170
- document.getElementById('topBottomControlsExample').setData({
171
- records: contacts.slice(10, 20),
172
- controls: {
173
- top: [
174
- {
175
- icon: 'add',
176
- action: (table) => table.addRecord(generateContact())
177
- }
178
- ],
179
- bottom: [
180
- {
181
- icon: 'refresh',
182
- action: (table) => {
183
- contacts = contacts.sort(() => Math.random() - 0.5);
184
- table.setRecords(contacts.slice(0, 10));
185
- }
186
- }
187
- ]
188
- }
189
- });
190
- </script>
191
-
192
- <h3 id="rowControls"><a href="#rowControls" class="no-link">Row Controls</a></h3>
193
- <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>
194
- <pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">k-table</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"rowControlsExample"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">k-table</span>&gt;</span><br /><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>&gt;</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">'&lt;span&gt;Custom HTML&lt;/span&gt; '</span><br /> },<br /> {<br /> <span class="hljs-attr">render</span>: <span class="hljs-function">(<span class="hljs-params">table, record</span>) =&gt;</span> {<br /> <span class="hljs-keyword">return</span> <span class="hljs-string">`&lt;button onclick="alert('<span class="hljs-subst">${record.name}</span>')"&gt;Alert&lt;/button&gt;`</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>) =&gt;</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>) =&gt;</span> {<br /> table.deleteRecord(index);<br /> }<br /> }<br /> ]<br /> }<br /> });<br /></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></code></pre>
195
- <k-table id="rowControlsExample"></k-table>
196
- <script type="module">
197
- document.getElementById('rowControlsExample').setData({
198
- records: contacts.slice(20, 25),
199
- controls: {
200
- before: [
201
- {
202
- html: '<span>Custom HTML</span> '
203
- },
204
- {
205
- render: (table, record) => {
206
- return `<button onclick="alert('${record.name}')">Alert</button>`;
207
- }
208
- }
209
- ],
210
- after: [
211
- {
212
- icon: 'edit',
213
- action: (table, record, index) => {
214
- const newName = prompt("Enter a new name:", record.name);
215
- if (newName) {
216
- record.name = newName;
217
- table.updateRecord(index, record);
218
- }
219
- }
220
- },
221
- {
222
- icon: 'delete',
223
- action: (table, record, index) => {
224
- table.deleteRecord(index);
225
- }
226
- }
227
- ]
228
- }
229
- });
230
- </script>
231
-
232
-
233
- <h3 id="pagination"><a href="#pagination" class="no-link">Pagination</a></h3>
234
- <p>The table component supports pagination. You can set the page size and navigate through pages using the provided methods.</p>
235
- <p>There are some predefined controls that you can use directly from <code>Table.controls</code>. These controls include:</p>
126
+ <h3>Examples</h3>
236
127
  <ul>
237
- <li><code>prevPage</code>: A control to navigate to the previous page.</li>
238
- <li><code>nextPage</code>: A control to navigate to the next page.</li>
239
- <li><code>pageSelect</code>: A control to select a specific page.</li>
240
- <li><code>spacer</code>: A spacer that flexes to separate the other controls to before it to the left, and after it to the far right.</li>
241
- <li><code>pageSize</code>: A control to select the number of records per page.</li>
128
+ <li><a href="tableCustomFields.html">Custom Fields Example</a></li>
129
+ <li><a href="tableControls.html">Top and Bottom Controls</a></li>
130
+ <li><a href="tableRowControls.html">Row Controls</a></li>
131
+ <li><a href="tablePagination.html">Pagination</a></li>
132
+ <li><a href="tableRecordSelection.html">Record Selection</a></li>
133
+ <li><a href="tableRecordEditing.html">Record Editing</a></li>
134
+ <li><a href="tableRecordHiding.html">Record Hiding</a></li>
135
+ <li><a href="tableRecordFiltering.html">Record Filtering</a></li>
136
+ <li><a href="tableRecordSearching.html">Record Searching</a></li>
137
+ <li><a href="tableSorting.html">Sorting</a></li>
138
+ <li><a href="tableFieldSortHide.html">Field Sorting and Hiding</a></li>
139
+ <li><a href="tableFetchRecords.html">Fetching Records</a></li>
242
140
  </ul>
243
- <pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">k-table</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"paginationExample"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">k-table</span>&gt;</span><br /><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>&gt;</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">&lt;/<span class="hljs-name">script</span>&gt;</span></code></pre>
244
- <k-table id="paginationExample"></k-table>
245
- <script type="module">
246
- import Table from '../kempo/components/Table.js';
247
- const $paginationExample = document.getElementById('paginationExample');
248
- $paginationExample.setData({
249
- records: contacts,
250
- controls: {
251
- bottom: [
252
- Table.controls.prevPage,
253
- Table.controls.nextPage,
254
- Table.controls.pageSelect,
255
- Table.controls.spacer,
256
- Table.controls.pageSize
257
- ]
258
- },
259
- pageSize: 10,
260
- pageSizeOptions: [5, 10, 20]
261
- });
262
- </script>
263
-
264
- <h3 id="recordSelection"><a href="#recordSelection" class="no-link">Record Selection</a></h3>
265
- <p>The table component supports record selection. You can enable selection by setting the <code>enableSelection</code> property to <code>true</code>. This will add a checkbox to each row and a "Select All" checkbox to the header.</p>
266
- <pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">k-table</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"recordSelectionExample"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">k-table</span>&gt;</span><br /><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>&gt;</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-built_in">document</span>.getElementById(<span class="hljs-string">'recordSelectionExample'</span>).setData({<br /> <span class="hljs-attr">records</span>: contacts,<br /> <span class="hljs-attr">enableSelection</span>: <span class="hljs-literal">true</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.selectCount,<br /> Table.controls.deleteSelected<br /> ]<br /> },<br /> <span class="hljs-attr">pageSize</span>: <span class="hljs-number">10</span><br /> });<br /></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></code></pre>
267
- <k-table id="recordSelectionExample"></k-table>
268
- <script type="module">
269
- import Table from '../kempo/components/Table.js';
270
- document.getElementById('recordSelectionExample').setData({
271
- records: contacts,
272
- enableSelection: true,
273
- controls: {
274
- bottom: [
275
- Table.controls.prevPage,
276
- Table.controls.nextPage,
277
- Table.controls.pageSelect,
278
- Table.controls.spacer,
279
- Table.controls.selectCount,
280
- Table.controls.deleteSelected
281
- ]
282
- },
283
- pageSize: 10
284
- });
285
- </script>
286
141
 
287
142
  <br />
288
143
  <hr class="my" />
@@ -334,9 +189,12 @@
334
189
  <ul>
335
190
  <li><code>records</code>: An array of objects representing the records to be shown in the table.</li>
336
191
  <li><code>fields</code>: An array of objects representing the fields of the table, each object must contain a <code>name</code> and a <code>label</code>. If this property is omitted, the fields will be automatically generated from the first 100 records.</li>
337
- <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>
192
+ <li><code>filters</code>: An array of filter objects to apply to the records.</li>
338
193
  <li><code>pageSize</code>: The number of records to display per page.</li>
339
194
  <li><code>pageSizeOptions</code>: An array of numbers representing the available page size options.</li>
195
+ <li><code>currentPage</code>: The current page to display.</li>
196
+ <li><code>enableSelection</code>: A boolean to enable or disable record selection.</li>
197
+ <li><code>enablePages</code>: A boolean to enable or disable pagination.</li>
340
198
  </ul>
341
199
 
342
200
  <h5><code>renderFields()<i>: undefined</i></code></h5>
@@ -348,11 +206,11 @@
348
206
  <h5><code>addRecord(<i>object</i> record)<i>: undefined</i></code></h5>
349
207
  <p>Adds a new record to the table.</p>
350
208
 
351
- <h5><code>updateRecord(<i>number</i> index, <i>object</i> record)<i>: undefined</i></code></h5>
352
- <p>Updates an existing record at the specified index.</p>
209
+ <h5><code>updateRecord(<i>object</i> record, <i>object</i> newData)<i>: undefined</i></code></h5>
210
+ <p>Updates an existing record with new data.</p>
353
211
 
354
- <h5><code>deleteRecord(<i>number</i> index)<i>: undefined</i></code></h5>
355
- <p>Deletes a record at the specified index.</p>
212
+ <h5><code>deleteRecord(<i>object</i> record)<i>: undefined</i></code></h5>
213
+ <p>Deletes a record from the table.</p>
356
214
 
357
215
  <h5><code>setRecords(<i>Array</i> records)<i>: undefined</i></code></h5>
358
216
  <p>Sets the records for the table and re-renders the rows.</p>
@@ -360,13 +218,25 @@
360
218
  <h5><code>setPageSize(<i>number</i> pageSize)<i>: undefined</i></code></h5>
361
219
  <p>Sets the number of records to display per page.</p>
362
220
 
363
- <h5><code>goToPage(<i>number</i> pageNumber)<i>: undefined</i></code></h5>
364
- <p>Navigates to the specified page number.</p>
221
+ <h5><code>setPage(<i>number</i> page)<i>: undefined</i></code></h5>
222
+ <p>Sets the current page to display.</p>
223
+
224
+ <h5><code>nextPage()<i>: undefined</i></code></h5>
225
+ <p>Moves to the next page.</p>
226
+
227
+ <h5><code>prevPage()<i>: undefined</i></code></h5>
228
+ <p>Moves to the previous page.</p>
229
+
230
+ <h5><code>getCurrentPage()<i>: number</i></code></h5>
231
+ <p>Returns the current page number.</p>
232
+
233
+ <h5><code>getTotalPages()<i>: number</i></code></h5>
234
+ <p>Returns the total number of pages.</p>
365
235
 
366
236
  <h5><code>getSelectedRecords()<i>: Array</i></code></h5>
367
237
  <p>Returns an array of the currently selected records.</p>
368
238
 
369
- <h5><code>deleteSelectedRecords()<i>: undefined</i></code></h5>
239
+ <h5><code>deleteSelected()<i>: undefined</i></code></h5>
370
240
  <p>Deletes all currently selected records from the table.</p>
371
241
 
372
242
  <h5><code>selectAllOnPage()<i>: undefined</i></code></h5>
@@ -375,9 +245,65 @@
375
245
  <h5><code>deselectAllOnPage()<i>: undefined</i></code></h5>
376
246
  <p>Deselects all the records on the current page.</p>
377
247
 
378
- <h5><code>allOnPageSelected()<i>: undefined</i></code></h5>
248
+ <h5><code>allOnPageSelected()<i>: boolean</i></code></h5>
379
249
  <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
-
250
+
251
+ <h5><code>editRecord(<i>object</i> record)<i>: undefined</i></code></h5>
252
+ <p>Enables editing mode for a record.</p>
253
+
254
+ <h5><code>saveEditedRecord(<i>object</i> record)<i>: undefined</i></code></h5>
255
+ <p>Saves the changes made to an edited record.</p>
256
+
257
+ <h5><code>cancelEditedRecord(<i>object</i> record)<i>: undefined</i></code></h5>
258
+ <p>Cancels the editing mode for a record.</p>
259
+
260
+ <h5><code>recordIsEditing(<i>object</i> record)<i>: boolean</i></code></h5>
261
+ <p>Returns <code>true</code> if the record is in editing mode, and <code>false</code> if it is not.</p>
262
+
263
+ <h5><code>hideRecord(<i>object</i> record)<i>: undefined</i></code></h5>
264
+ <p>Hides a record from the table.</p>
265
+
266
+ <h5><code>showRecord(<i>object</i> record)<i>: undefined</i></code></h5>
267
+ <p>Shows a hidden record in the table.</p>
268
+
269
+ <h5><code>showAllRecords()<i>: undefined</i></code></h5>
270
+ <p>Shows all hidden records in the table.</p>
271
+
272
+ <h5><code>addFilter(<i>string</i> field, <i>string</i> condition, <i>any</i> value)<i>: undefined</i></code></h5>
273
+ <p>Adds a filter to the table.</p>
274
+
275
+ <h5><code>removeFilter(<i>string</i> field, <i>string</i> condition, <i>any</i> value)<i>: undefined</i></code></h5>
276
+ <p>Removes a filter from the table.</p>
277
+
278
+ <h5><code>removeAllFilters()<i>: undefined</i></code></h5>
279
+ <p>Removes all filters from the table.</p>
280
+
281
+ <h5><code>search(<i>string</i> term)<i>: undefined</i></code></h5>
282
+ <p>Searches the records for the specified term.</p>
283
+
284
+ <h5><code>getDisplayedRecords()<i>: Array</i></code></h5>
285
+ <p>Returns an array of the records currently displayed in the table.</p>
286
+
287
+ <h5><code>getHiddenRecords()<i>: Array</i></code></h5>
288
+ <p>Returns an array of the hidden records in the table.</p>
289
+
290
+ <h5><code>setupFetchRecords(<i>number</i> totalRecords, <i>function</i> callback)<i>: undefined</i></code></h5>
291
+ <p>Sets up the table to fetch records dynamically.</p>
292
+
293
+ <h5><code>sortBy(<i>string</i> field, <i>boolean</i> asc)<i>: undefined</i></code></h5>
294
+ <p>Sorts the records by the specified field in ascending or descending order.</p>
295
+
296
+ <h5><code>setFieldHiddenState(<i>string</i> fieldName, <i>boolean</i> hidden)<i>: undefined</i></code></h5>
297
+ <p>Sets the hidden state of a field.</p>
298
+
299
+ <h5><code>hideField(<i>string</i> fieldName)<i>: undefined</i></code></h5>
300
+ <p>Hides a field in the table.</p>
301
+
302
+ <h5><code>showField(<i>string</i> fieldName)<i>: undefined</i></code></h5>
303
+ <p>Shows a hidden field in the table.</p>
304
+
305
+ <h5><code>reorderFields(<i>Array</i> newOrder)<i>: undefined</i></code></h5>
306
+ <p>Reorders the fields in the table based on the new order array.</p>
381
307
 
382
308
  </main>
383
309
  <div style="height: 33.333vh"></div>
@@ -0,0 +1,77 @@
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 < 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 - 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 supports controls at both the top and bottom. These controls can handle pagination, adding new records, or other actions. They are web components that interact with their parent <code>k-table</code> by accessing its methods and listening for its events.</p>
63
+ <pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">k-table</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"topBottomControlsExample"</span>&gt;</span><br /> <span class="hljs-tag">&lt;<span class="hljs-name">k-tc-export-json</span> <span class="hljs-attr">slot</span>=<span class="hljs-string">"top"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">k-tc-export-json</span>&gt;</span><br /> <span class="hljs-tag">&lt;<span class="hljs-name">k-tc-export-csv</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">k-tc-export-csv</span>&gt;</span><br /><span class="hljs-tag">&lt;/<span class="hljs-name">k-table</span>&gt;</span><br /><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"../kempo/components/tableControls/ExportJson.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span><br /><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"../kempo/components/tableControls/ExportCsv.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span><br /><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>&gt;</span><span class="javascript"><br /> <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'topBottomControlsExample'</span>).setRecords(contacts);<br /></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></code></pre>
64
+ <k-table id="topBottomControlsExample">
65
+ <k-tc-export-json slot="top"></k-tc-export-json>
66
+ <k-tc-export-csv></k-tc-export-csv>
67
+ </k-table>
68
+ <script type="module" src="../kempo/components/tableControls/ExportJson.js"></script>
69
+ <script type="module" src="../kempo/components/tableControls/ExportCsv.js"></script>
70
+ <script type="module">
71
+ document.getElementById('topBottomControlsExample').setRecords(contacts);
72
+ </script>
73
+ </main>
74
+ <div style="height: 33.333vh"></div>
75
+ <script type="module" src="../kempo/components/Import.js"></script>
76
+ </body>
77
+ </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">&lt;<span class="hljs-name">k-table</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"customFieldsExample"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">k-table</span>&gt;</span><br /><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>&gt;</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>) =&gt;</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 &lt; <span class="hljs-number">0</span> || (monthDifference === <span class="hljs-number">0</span> &amp;&amp; today.getDate() &lt; 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>) =&gt;</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">&lt;/<span class="hljs-name">script</span>&gt;</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>