@keenthemes/ktui 1.0.3
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/CONTRIBUTING.md +88 -0
- package/LICENSE.md +21 -0
- package/README.md +124 -0
- package/dist/ktui.js +19201 -0
- package/dist/ktui.min.js +2 -0
- package/dist/ktui.min.js.map +1 -0
- package/lib/cjs/components/accordion/accordion.js +168 -0
- package/lib/cjs/components/accordion/accordion.js.map +1 -0
- package/lib/cjs/components/accordion/index.js +6 -0
- package/lib/cjs/components/accordion/index.js.map +1 -0
- package/lib/cjs/components/accordion/types.js +3 -0
- package/lib/cjs/components/accordion/types.js.map +1 -0
- package/lib/cjs/components/collapse/collapse.js +169 -0
- package/lib/cjs/components/collapse/collapse.js.map +1 -0
- package/lib/cjs/components/collapse/index.js +6 -0
- package/lib/cjs/components/collapse/index.js.map +1 -0
- package/lib/cjs/components/collapse/types.js +3 -0
- package/lib/cjs/components/collapse/types.js.map +1 -0
- package/lib/cjs/components/component.js +135 -0
- package/lib/cjs/components/component.js.map +1 -0
- package/lib/cjs/components/config.js +26 -0
- package/lib/cjs/components/config.js.map +1 -0
- package/lib/cjs/components/config.umd.js +23 -0
- package/lib/cjs/components/config.umd.js.map +1 -0
- package/lib/cjs/components/constants.js +15 -0
- package/lib/cjs/components/constants.js.map +1 -0
- package/lib/cjs/components/datatable/datatable.js +1464 -0
- package/lib/cjs/components/datatable/datatable.js.map +1 -0
- package/lib/cjs/components/datatable/index.js +6 -0
- package/lib/cjs/components/datatable/index.js.map +1 -0
- package/lib/cjs/components/datatable/types.js +3 -0
- package/lib/cjs/components/datatable/types.js.map +1 -0
- package/lib/cjs/components/dismiss/dismiss.js +131 -0
- package/lib/cjs/components/dismiss/dismiss.js.map +1 -0
- package/lib/cjs/components/dismiss/index.js +6 -0
- package/lib/cjs/components/dismiss/index.js.map +1 -0
- package/lib/cjs/components/dismiss/types.js +3 -0
- package/lib/cjs/components/dismiss/types.js.map +1 -0
- package/lib/cjs/components/drawer/drawer.js +347 -0
- package/lib/cjs/components/drawer/drawer.js.map +1 -0
- package/lib/cjs/components/drawer/index.js +6 -0
- package/lib/cjs/components/drawer/index.js.map +1 -0
- package/lib/cjs/components/drawer/types.js +3 -0
- package/lib/cjs/components/drawer/types.js.map +1 -0
- package/lib/cjs/components/dropdown/dropdown.js +403 -0
- package/lib/cjs/components/dropdown/dropdown.js.map +1 -0
- package/lib/cjs/components/dropdown/index.js +6 -0
- package/lib/cjs/components/dropdown/index.js.map +1 -0
- package/lib/cjs/components/dropdown/types.js +3 -0
- package/lib/cjs/components/dropdown/types.js.map +1 -0
- package/lib/cjs/components/image-input/image-input.js +191 -0
- package/lib/cjs/components/image-input/image-input.js.map +1 -0
- package/lib/cjs/components/image-input/index.js +6 -0
- package/lib/cjs/components/image-input/index.js.map +1 -0
- package/lib/cjs/components/image-input/types.js +3 -0
- package/lib/cjs/components/image-input/types.js.map +1 -0
- package/lib/cjs/components/menu/index.js +6 -0
- package/lib/cjs/components/menu/index.js.map +1 -0
- package/lib/cjs/components/menu/menu.js +1021 -0
- package/lib/cjs/components/menu/menu.js.map +1 -0
- package/lib/cjs/components/menu/types.js +3 -0
- package/lib/cjs/components/menu/types.js.map +1 -0
- package/lib/cjs/components/modal/index.js +6 -0
- package/lib/cjs/components/modal/index.js.map +1 -0
- package/lib/cjs/components/modal/modal.js +316 -0
- package/lib/cjs/components/modal/modal.js.map +1 -0
- package/lib/cjs/components/modal/types.js +3 -0
- package/lib/cjs/components/modal/types.js.map +1 -0
- package/lib/cjs/components/reparent/index.js +6 -0
- package/lib/cjs/components/reparent/index.js.map +1 -0
- package/lib/cjs/components/reparent/reparent.js +93 -0
- package/lib/cjs/components/reparent/reparent.js.map +1 -0
- package/lib/cjs/components/reparent/types.js +3 -0
- package/lib/cjs/components/reparent/types.js.map +1 -0
- package/lib/cjs/components/scrollable/index.js +6 -0
- package/lib/cjs/components/scrollable/index.js.map +1 -0
- package/lib/cjs/components/scrollable/scrollable.js +259 -0
- package/lib/cjs/components/scrollable/scrollable.js.map +1 -0
- package/lib/cjs/components/scrollable/types.js +3 -0
- package/lib/cjs/components/scrollable/types.js.map +1 -0
- package/lib/cjs/components/scrollspy/index.js +6 -0
- package/lib/cjs/components/scrollspy/index.js.map +1 -0
- package/lib/cjs/components/scrollspy/scrollspy.js +174 -0
- package/lib/cjs/components/scrollspy/scrollspy.js.map +1 -0
- package/lib/cjs/components/scrollspy/types.js +3 -0
- package/lib/cjs/components/scrollspy/types.js.map +1 -0
- package/lib/cjs/components/scrollto/index.js +6 -0
- package/lib/cjs/components/scrollto/index.js.map +1 -0
- package/lib/cjs/components/scrollto/scrollto.js +103 -0
- package/lib/cjs/components/scrollto/scrollto.js.map +1 -0
- package/lib/cjs/components/scrollto/types.js +3 -0
- package/lib/cjs/components/scrollto/types.js.map +1 -0
- package/lib/cjs/components/stepper/index.js +6 -0
- package/lib/cjs/components/stepper/index.js.map +1 -0
- package/lib/cjs/components/stepper/stepper.js +258 -0
- package/lib/cjs/components/stepper/stepper.js.map +1 -0
- package/lib/cjs/components/stepper/types.js +3 -0
- package/lib/cjs/components/stepper/types.js.map +1 -0
- package/lib/cjs/components/sticky/index.js +6 -0
- package/lib/cjs/components/sticky/index.js.map +1 -0
- package/lib/cjs/components/sticky/sticky.js +297 -0
- package/lib/cjs/components/sticky/sticky.js.map +1 -0
- package/lib/cjs/components/sticky/types.js +3 -0
- package/lib/cjs/components/sticky/types.js.map +1 -0
- package/lib/cjs/components/tabs/index.js +6 -0
- package/lib/cjs/components/tabs/index.js.map +1 -0
- package/lib/cjs/components/tabs/tabs.js +146 -0
- package/lib/cjs/components/tabs/tabs.js.map +1 -0
- package/lib/cjs/components/tabs/types.js +3 -0
- package/lib/cjs/components/tabs/types.js.map +1 -0
- package/lib/cjs/components/theme/index.js +6 -0
- package/lib/cjs/components/theme/index.js.map +1 -0
- package/lib/cjs/components/theme/theme.js +147 -0
- package/lib/cjs/components/theme/theme.js.map +1 -0
- package/lib/cjs/components/theme/types.js +3 -0
- package/lib/cjs/components/theme/types.js.map +1 -0
- package/lib/cjs/components/toggle/index.js +6 -0
- package/lib/cjs/components/toggle/index.js.map +1 -0
- package/lib/cjs/components/toggle/toggle.js +139 -0
- package/lib/cjs/components/toggle/toggle.js.map +1 -0
- package/lib/cjs/components/toggle/types.js +3 -0
- package/lib/cjs/components/toggle/types.js.map +1 -0
- package/lib/cjs/components/toggle-password/index.js +6 -0
- package/lib/cjs/components/toggle-password/index.js.map +1 -0
- package/lib/cjs/components/toggle-password/toggle-password.js +131 -0
- package/lib/cjs/components/toggle-password/toggle-password.js.map +1 -0
- package/lib/cjs/components/toggle-password/types.js +3 -0
- package/lib/cjs/components/toggle-password/types.js.map +1 -0
- package/lib/cjs/components/tooltip/index.js +6 -0
- package/lib/cjs/components/tooltip/index.js.map +1 -0
- package/lib/cjs/components/tooltip/tooltip.js +271 -0
- package/lib/cjs/components/tooltip/tooltip.js.map +1 -0
- package/lib/cjs/components/tooltip/types.js +3 -0
- package/lib/cjs/components/tooltip/types.js.map +1 -0
- package/lib/cjs/helpers/data.js +33 -0
- package/lib/cjs/helpers/data.js.map +1 -0
- package/lib/cjs/helpers/dom.js +297 -0
- package/lib/cjs/helpers/dom.js.map +1 -0
- package/lib/cjs/helpers/event-handler.js +36 -0
- package/lib/cjs/helpers/event-handler.js.map +1 -0
- package/lib/cjs/helpers/utils.js +94 -0
- package/lib/cjs/helpers/utils.js.map +1 -0
- package/lib/cjs/index.js +105 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/types.js +3 -0
- package/lib/cjs/types.js.map +1 -0
- package/lib/esm/components/accordion/accordion.js +165 -0
- package/lib/esm/components/accordion/accordion.js.map +1 -0
- package/lib/esm/components/accordion/index.js +2 -0
- package/lib/esm/components/accordion/index.js.map +1 -0
- package/lib/esm/components/accordion/types.js +2 -0
- package/lib/esm/components/accordion/types.js.map +1 -0
- package/lib/esm/components/collapse/collapse.js +166 -0
- package/lib/esm/components/collapse/collapse.js.map +1 -0
- package/lib/esm/components/collapse/index.js +2 -0
- package/lib/esm/components/collapse/index.js.map +1 -0
- package/lib/esm/components/collapse/types.js +2 -0
- package/lib/esm/components/collapse/types.js.map +1 -0
- package/lib/esm/components/component.js +133 -0
- package/lib/esm/components/component.js.map +1 -0
- package/lib/esm/components/config.js +24 -0
- package/lib/esm/components/config.js.map +1 -0
- package/lib/esm/components/config.umd.js +23 -0
- package/lib/esm/components/config.umd.js.map +1 -0
- package/lib/esm/components/constants.js +12 -0
- package/lib/esm/components/constants.js.map +1 -0
- package/lib/esm/components/datatable/datatable.js +1461 -0
- package/lib/esm/components/datatable/datatable.js.map +1 -0
- package/lib/esm/components/datatable/index.js +2 -0
- package/lib/esm/components/datatable/index.js.map +1 -0
- package/lib/esm/components/datatable/types.js +2 -0
- package/lib/esm/components/datatable/types.js.map +1 -0
- package/lib/esm/components/dismiss/dismiss.js +128 -0
- package/lib/esm/components/dismiss/dismiss.js.map +1 -0
- package/lib/esm/components/dismiss/index.js +2 -0
- package/lib/esm/components/dismiss/index.js.map +1 -0
- package/lib/esm/components/dismiss/types.js +2 -0
- package/lib/esm/components/dismiss/types.js.map +1 -0
- package/lib/esm/components/drawer/drawer.js +344 -0
- package/lib/esm/components/drawer/drawer.js.map +1 -0
- package/lib/esm/components/drawer/index.js +2 -0
- package/lib/esm/components/drawer/index.js.map +1 -0
- package/lib/esm/components/drawer/types.js +2 -0
- package/lib/esm/components/drawer/types.js.map +1 -0
- package/lib/esm/components/dropdown/dropdown.js +400 -0
- package/lib/esm/components/dropdown/dropdown.js.map +1 -0
- package/lib/esm/components/dropdown/index.js +2 -0
- package/lib/esm/components/dropdown/index.js.map +1 -0
- package/lib/esm/components/dropdown/types.js +2 -0
- package/lib/esm/components/dropdown/types.js.map +1 -0
- package/lib/esm/components/image-input/image-input.js +188 -0
- package/lib/esm/components/image-input/image-input.js.map +1 -0
- package/lib/esm/components/image-input/index.js +2 -0
- package/lib/esm/components/image-input/index.js.map +1 -0
- package/lib/esm/components/image-input/types.js +2 -0
- package/lib/esm/components/image-input/types.js.map +1 -0
- package/lib/esm/components/menu/index.js +2 -0
- package/lib/esm/components/menu/index.js.map +1 -0
- package/lib/esm/components/menu/menu.js +1018 -0
- package/lib/esm/components/menu/menu.js.map +1 -0
- package/lib/esm/components/menu/types.js +2 -0
- package/lib/esm/components/menu/types.js.map +1 -0
- package/lib/esm/components/modal/index.js +2 -0
- package/lib/esm/components/modal/index.js.map +1 -0
- package/lib/esm/components/modal/modal.js +313 -0
- package/lib/esm/components/modal/modal.js.map +1 -0
- package/lib/esm/components/modal/types.js +2 -0
- package/lib/esm/components/modal/types.js.map +1 -0
- package/lib/esm/components/reparent/index.js +2 -0
- package/lib/esm/components/reparent/index.js.map +1 -0
- package/lib/esm/components/reparent/reparent.js +90 -0
- package/lib/esm/components/reparent/reparent.js.map +1 -0
- package/lib/esm/components/reparent/types.js +2 -0
- package/lib/esm/components/reparent/types.js.map +1 -0
- package/lib/esm/components/scrollable/index.js +2 -0
- package/lib/esm/components/scrollable/index.js.map +1 -0
- package/lib/esm/components/scrollable/scrollable.js +256 -0
- package/lib/esm/components/scrollable/scrollable.js.map +1 -0
- package/lib/esm/components/scrollable/types.js +2 -0
- package/lib/esm/components/scrollable/types.js.map +1 -0
- package/lib/esm/components/scrollspy/index.js +2 -0
- package/lib/esm/components/scrollspy/index.js.map +1 -0
- package/lib/esm/components/scrollspy/scrollspy.js +171 -0
- package/lib/esm/components/scrollspy/scrollspy.js.map +1 -0
- package/lib/esm/components/scrollspy/types.js +2 -0
- package/lib/esm/components/scrollspy/types.js.map +1 -0
- package/lib/esm/components/scrollto/index.js +2 -0
- package/lib/esm/components/scrollto/index.js.map +1 -0
- package/lib/esm/components/scrollto/scrollto.js +100 -0
- package/lib/esm/components/scrollto/scrollto.js.map +1 -0
- package/lib/esm/components/scrollto/types.js +2 -0
- package/lib/esm/components/scrollto/types.js.map +1 -0
- package/lib/esm/components/stepper/index.js +2 -0
- package/lib/esm/components/stepper/index.js.map +1 -0
- package/lib/esm/components/stepper/stepper.js +255 -0
- package/lib/esm/components/stepper/stepper.js.map +1 -0
- package/lib/esm/components/stepper/types.js +2 -0
- package/lib/esm/components/stepper/types.js.map +1 -0
- package/lib/esm/components/sticky/index.js +2 -0
- package/lib/esm/components/sticky/index.js.map +1 -0
- package/lib/esm/components/sticky/sticky.js +294 -0
- package/lib/esm/components/sticky/sticky.js.map +1 -0
- package/lib/esm/components/sticky/types.js +2 -0
- package/lib/esm/components/sticky/types.js.map +1 -0
- package/lib/esm/components/tabs/index.js +2 -0
- package/lib/esm/components/tabs/index.js.map +1 -0
- package/lib/esm/components/tabs/tabs.js +143 -0
- package/lib/esm/components/tabs/tabs.js.map +1 -0
- package/lib/esm/components/tabs/types.js +2 -0
- package/lib/esm/components/tabs/types.js.map +1 -0
- package/lib/esm/components/theme/index.js +2 -0
- package/lib/esm/components/theme/index.js.map +1 -0
- package/lib/esm/components/theme/theme.js +144 -0
- package/lib/esm/components/theme/theme.js.map +1 -0
- package/lib/esm/components/theme/types.js +2 -0
- package/lib/esm/components/theme/types.js.map +1 -0
- package/lib/esm/components/toggle/index.js +2 -0
- package/lib/esm/components/toggle/index.js.map +1 -0
- package/lib/esm/components/toggle/toggle.js +136 -0
- package/lib/esm/components/toggle/toggle.js.map +1 -0
- package/lib/esm/components/toggle/types.js +2 -0
- package/lib/esm/components/toggle/types.js.map +1 -0
- package/lib/esm/components/toggle-password/index.js +2 -0
- package/lib/esm/components/toggle-password/index.js.map +1 -0
- package/lib/esm/components/toggle-password/toggle-password.js +128 -0
- package/lib/esm/components/toggle-password/toggle-password.js.map +1 -0
- package/lib/esm/components/toggle-password/types.js +2 -0
- package/lib/esm/components/toggle-password/types.js.map +1 -0
- package/lib/esm/components/tooltip/index.js +2 -0
- package/lib/esm/components/tooltip/index.js.map +1 -0
- package/lib/esm/components/tooltip/tooltip.js +268 -0
- package/lib/esm/components/tooltip/tooltip.js.map +1 -0
- package/lib/esm/components/tooltip/types.js +2 -0
- package/lib/esm/components/tooltip/types.js.map +1 -0
- package/lib/esm/helpers/data.js +31 -0
- package/lib/esm/helpers/data.js.map +1 -0
- package/lib/esm/helpers/dom.js +295 -0
- package/lib/esm/helpers/dom.js.map +1 -0
- package/lib/esm/helpers/event-handler.js +34 -0
- package/lib/esm/helpers/event-handler.js.map +1 -0
- package/lib/esm/helpers/utils.js +92 -0
- package/lib/esm/helpers/utils.js.map +1 -0
- package/lib/esm/index.js +79 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/types.js +2 -0
- package/lib/esm/types.js.map +1 -0
- package/package.json +85 -0
- package/prettier.config.js +9 -0
- package/src/components/accordion/accordion-menu.css +51 -0
- package/src/components/accordion/accordion.css +86 -0
- package/src/components/accordion/accordion.ts +221 -0
- package/src/components/accordion/index.ts +7 -0
- package/src/components/accordion/types.ts +16 -0
- package/src/components/alert/alert.css +282 -0
- package/src/components/avatar/avatar.css +46 -0
- package/src/components/badge/badge.css +176 -0
- package/src/components/breadcrumb/breadcrumb.css +38 -0
- package/src/components/btn/btn.css +227 -0
- package/src/components/card/card.css +158 -0
- package/src/components/checkbox/checkbox.css +74 -0
- package/src/components/collapse/collapse.css +14 -0
- package/src/components/collapse/collapse.ts +200 -0
- package/src/components/collapse/index.ts +7 -0
- package/src/components/collapse/types.ts +16 -0
- package/src/components/component.ts +132 -0
- package/src/components/constants.ts +16 -0
- package/src/components/datatable/datatable-checkbox.ts +236 -0
- package/src/components/datatable/datatable-sort.ts +154 -0
- package/src/components/datatable/datatable.css +110 -0
- package/src/components/datatable/datatable.ts +1657 -0
- package/src/components/datatable/index.ts +19 -0
- package/src/components/datatable/types.ts +203 -0
- package/src/components/datepicker/calendar.ts +1397 -0
- package/src/components/datepicker/config.ts +368 -0
- package/src/components/datepicker/datepicker.css +7 -0
- package/src/components/datepicker/datepicker.ts +1287 -0
- package/src/components/datepicker/dropdown.ts +757 -0
- package/src/components/datepicker/events.ts +149 -0
- package/src/components/datepicker/index.ts +10 -0
- package/src/components/datepicker/keyboard.ts +646 -0
- package/src/components/datepicker/locales.ts +80 -0
- package/src/components/datepicker/templates.ts +792 -0
- package/src/components/datepicker/types.ts +154 -0
- package/src/components/datepicker/utils.ts +631 -0
- package/src/components/dismiss/dismiss.css +10 -0
- package/src/components/dismiss/dismiss.ts +152 -0
- package/src/components/dismiss/index.ts +7 -0
- package/src/components/dismiss/types.ts +17 -0
- package/src/components/drawer/drawer.css +97 -0
- package/src/components/drawer/drawer.ts +437 -0
- package/src/components/drawer/index.ts +7 -0
- package/src/components/drawer/types.ts +25 -0
- package/src/components/dropdown/dropdown-menu.css +56 -0
- package/src/components/dropdown/dropdown.css +46 -0
- package/src/components/dropdown/dropdown.ts +549 -0
- package/src/components/dropdown/index.ts +7 -0
- package/src/components/dropdown/types.ts +28 -0
- package/src/components/form/form.css +54 -0
- package/src/components/image-input/image-input.css +56 -0
- package/src/components/image-input/image-input.ts +249 -0
- package/src/components/image-input/index.ts +10 -0
- package/src/components/image-input/types.ts +12 -0
- package/src/components/input/input-group.css +42 -0
- package/src/components/input/input.css +136 -0
- package/src/components/kbd/kbd.css +30 -0
- package/src/components/label/label.css +20 -0
- package/src/components/link/link.css +81 -0
- package/src/components/modal/index.ts +7 -0
- package/src/components/modal/modal.css +73 -0
- package/src/components/modal/modal.ts +382 -0
- package/src/components/modal/types.ts +21 -0
- package/src/components/pagination/pagination.css +26 -0
- package/src/components/popover/popover.css +22 -0
- package/src/components/progress/progress.css +51 -0
- package/src/components/radio/radio.css +51 -0
- package/src/components/reparent/index.ts +7 -0
- package/src/components/reparent/reparent.ts +109 -0
- package/src/components/reparent/types.ts +15 -0
- package/src/components/scrollable/index.ts +10 -0
- package/src/components/scrollable/scrollable.css +29 -0
- package/src/components/scrollable/scrollable.ts +297 -0
- package/src/components/scrollable/types.ts +16 -0
- package/src/components/scrollspy/index.ts +7 -0
- package/src/components/scrollspy/scrollspy.css +13 -0
- package/src/components/scrollspy/scrollspy.ts +224 -0
- package/src/components/scrollspy/types.ts +15 -0
- package/src/components/scrollto/index.ts +7 -0
- package/src/components/scrollto/scrollto.ts +127 -0
- package/src/components/scrollto/types.ts +15 -0
- package/src/components/select/combobox.ts +305 -0
- package/src/components/select/config.ts +324 -0
- package/src/components/select/dropdown.ts +510 -0
- package/src/components/select/index.ts +13 -0
- package/src/components/select/option.ts +43 -0
- package/src/components/select/remote.ts +477 -0
- package/src/components/select/search.ts +430 -0
- package/src/components/select/select.css +105 -0
- package/src/components/select/select.ts +1916 -0
- package/src/components/select/tags.ts +123 -0
- package/src/components/select/templates.ts +531 -0
- package/src/components/select/types.ts +36 -0
- package/src/components/select/utils.ts +747 -0
- package/src/components/select/variants.css +5 -0
- package/src/components/separator/separator.css +14 -0
- package/src/components/skeleton/skeleton.css +10 -0
- package/src/components/stepper/index.ts +7 -0
- package/src/components/stepper/stepper.css +49 -0
- package/src/components/stepper/stepper.ts +308 -0
- package/src/components/stepper/types.ts +13 -0
- package/src/components/sticky/index.ts +7 -0
- package/src/components/sticky/sticky.css +22 -0
- package/src/components/sticky/sticky.ts +381 -0
- package/src/components/sticky/types.ts +23 -0
- package/src/components/switch/switch.css +110 -0
- package/src/components/table/table.css +168 -0
- package/src/components/tabs/index.ts +7 -0
- package/src/components/tabs/tabs.css +40 -0
- package/src/components/tabs/tabs.ts +190 -0
- package/src/components/tabs/types.ts +13 -0
- package/src/components/textarea/textarea.css +35 -0
- package/src/components/theme-switch/index.ts +10 -0
- package/src/components/theme-switch/theme-switch.css +22 -0
- package/src/components/theme-switch/theme-switch.ts +176 -0
- package/src/components/theme-switch/types.ts +15 -0
- package/src/components/toggle/index.ts +7 -0
- package/src/components/toggle/toggle.css +13 -0
- package/src/components/toggle/toggle.ts +173 -0
- package/src/components/toggle/types.ts +18 -0
- package/src/components/toggle-group/toggle-group.css +55 -0
- package/src/components/toggle-password/index.ts +10 -0
- package/src/components/toggle-password/toggle-password.css +13 -0
- package/src/components/toggle-password/toggle-password.ts +159 -0
- package/src/components/toggle-password/types.ts +13 -0
- package/src/components/tooltip/index.ts +7 -0
- package/src/components/tooltip/tooltip.css +18 -0
- package/src/components/tooltip/tooltip.ts +361 -0
- package/src/components/tooltip/types.ts +28 -0
- package/src/helpers/data.ts +46 -0
- package/src/helpers/dom.ts +405 -0
- package/src/helpers/event-handler.ts +61 -0
- package/src/helpers/utils.ts +183 -0
- package/src/index.ts +113 -0
- package/src/types.ts +23 -0
- package/styles.css +48 -0
- package/tsconfig.json +17 -0
- package/webpack.config.js +113 -0
|
@@ -0,0 +1,1461 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
var __assign = (this && this.__assign) || function () {
|
|
17
|
+
__assign = Object.assign || function(t) {
|
|
18
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
19
|
+
s = arguments[i];
|
|
20
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
21
|
+
t[p] = s[p];
|
|
22
|
+
}
|
|
23
|
+
return t;
|
|
24
|
+
};
|
|
25
|
+
return __assign.apply(this, arguments);
|
|
26
|
+
};
|
|
27
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
28
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
29
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
30
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
31
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
32
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
33
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
37
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
38
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
39
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
40
|
+
function step(op) {
|
|
41
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
42
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
43
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
44
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
45
|
+
switch (op[0]) {
|
|
46
|
+
case 0: case 1: t = op; break;
|
|
47
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
48
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
49
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
50
|
+
default:
|
|
51
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
52
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
53
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
54
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
55
|
+
if (t[2]) _.ops.pop();
|
|
56
|
+
_.trys.pop(); continue;
|
|
57
|
+
}
|
|
58
|
+
op = body.call(thisArg, _);
|
|
59
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
60
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
64
|
+
var t = {};
|
|
65
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
66
|
+
t[p] = s[p];
|
|
67
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
68
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
69
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
70
|
+
t[p[i]] = s[p[i]];
|
|
71
|
+
}
|
|
72
|
+
return t;
|
|
73
|
+
};
|
|
74
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
75
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
76
|
+
if (ar || !(i in from)) {
|
|
77
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
78
|
+
ar[i] = from[i];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
82
|
+
};
|
|
83
|
+
import KTComponent from '../component';
|
|
84
|
+
import KTEventHandler from '../../helpers/event-handler';
|
|
85
|
+
import KTUtils from '../../helpers/utils';
|
|
86
|
+
import KTComponents from '../../index';
|
|
87
|
+
import KTData from '../../helpers/data';
|
|
88
|
+
/**
|
|
89
|
+
* Custom DataTable plugin class with server-side API, pagination, and sorting
|
|
90
|
+
* @classdesc A custom KTComponent class that integrates server-side API, pagination, and sorting functionality into a table.
|
|
91
|
+
* It supports fetching data from a server-side API, pagination, and sorting of the fetched data.
|
|
92
|
+
* @class
|
|
93
|
+
* @extends {KTComponent}
|
|
94
|
+
* @param {HTMLElement} element The table element
|
|
95
|
+
* @param {KTDataTableConfigInterface} [config] Additional configuration options
|
|
96
|
+
*/
|
|
97
|
+
var KTDataTable = /** @class */ (function (_super) {
|
|
98
|
+
__extends(KTDataTable, _super);
|
|
99
|
+
function KTDataTable(element, config) {
|
|
100
|
+
var _this = _super.call(this) || this;
|
|
101
|
+
_this._name = 'datatable';
|
|
102
|
+
_this._checkboxListener = function (event) {
|
|
103
|
+
_this._checkboxToggle(event); // Toggle row checkbox state
|
|
104
|
+
};
|
|
105
|
+
// private _searchListener: (value: string) => void;
|
|
106
|
+
_this._data = [];
|
|
107
|
+
if (KTData.has(element, _this._name))
|
|
108
|
+
return _this;
|
|
109
|
+
_this._defaultConfig = _this._initDefaultConfig(config);
|
|
110
|
+
_this._init(element);
|
|
111
|
+
_this._buildConfig();
|
|
112
|
+
// Store the instance directly on the element
|
|
113
|
+
element.instance = _this;
|
|
114
|
+
_this._initElements();
|
|
115
|
+
if (_this._config.stateSave === false) {
|
|
116
|
+
_this._deleteState();
|
|
117
|
+
}
|
|
118
|
+
if (_this._config.stateSave) {
|
|
119
|
+
_this._loadState();
|
|
120
|
+
}
|
|
121
|
+
_this._initTableHeader();
|
|
122
|
+
_this._updateData();
|
|
123
|
+
_this._fireEvent('init');
|
|
124
|
+
_this._dispatchEvent('init');
|
|
125
|
+
return _this;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Initialize default configuration for the datatable
|
|
129
|
+
* @param config User-provided configuration options
|
|
130
|
+
* @returns Default configuration merged with user-provided options
|
|
131
|
+
*/
|
|
132
|
+
KTDataTable.prototype._initDefaultConfig = function (config) {
|
|
133
|
+
return __assign({
|
|
134
|
+
/**
|
|
135
|
+
* HTTP method for server-side API call
|
|
136
|
+
*/
|
|
137
|
+
requestMethod: 'GET',
|
|
138
|
+
/**
|
|
139
|
+
* Custom HTTP headers for the API request
|
|
140
|
+
*/
|
|
141
|
+
requestHeaders: {
|
|
142
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
143
|
+
},
|
|
144
|
+
/**
|
|
145
|
+
* Pagination info template
|
|
146
|
+
*/
|
|
147
|
+
info: '{start}-{end} of {total}',
|
|
148
|
+
/**
|
|
149
|
+
* Info text when there is no data
|
|
150
|
+
*/
|
|
151
|
+
infoEmpty: 'No records found',
|
|
152
|
+
/**
|
|
153
|
+
* Available page sizes
|
|
154
|
+
*/
|
|
155
|
+
pageSizes: [5, 10, 20, 30, 50],
|
|
156
|
+
/**
|
|
157
|
+
* Default page size
|
|
158
|
+
*/
|
|
159
|
+
pageSize: 10,
|
|
160
|
+
/**
|
|
161
|
+
* Enable or disable pagination more button
|
|
162
|
+
*/
|
|
163
|
+
pageMore: true,
|
|
164
|
+
/**
|
|
165
|
+
* Maximum number of pages before enabling pagination more button
|
|
166
|
+
*/
|
|
167
|
+
pageMoreLimit: 3,
|
|
168
|
+
/**
|
|
169
|
+
* Pagination button templates
|
|
170
|
+
*/
|
|
171
|
+
pagination: {
|
|
172
|
+
number: {
|
|
173
|
+
/**
|
|
174
|
+
* CSS classes to be added to the pagination button
|
|
175
|
+
*/
|
|
176
|
+
class: 'btn',
|
|
177
|
+
/**
|
|
178
|
+
* Text to be displayed in the pagination button
|
|
179
|
+
*/
|
|
180
|
+
text: '{page}',
|
|
181
|
+
},
|
|
182
|
+
previous: {
|
|
183
|
+
/**
|
|
184
|
+
* CSS classes to be added to the previous pagination button
|
|
185
|
+
*/
|
|
186
|
+
class: 'btn',
|
|
187
|
+
/**
|
|
188
|
+
* Text to be displayed in the previous pagination button
|
|
189
|
+
*/
|
|
190
|
+
text: '<i class="ki-outline ki-black-left"></i>',
|
|
191
|
+
},
|
|
192
|
+
next: {
|
|
193
|
+
/**
|
|
194
|
+
* CSS classes to be added to the next pagination button
|
|
195
|
+
*/
|
|
196
|
+
class: 'btn',
|
|
197
|
+
/**
|
|
198
|
+
* Text to be displayed in the next pagination button
|
|
199
|
+
*/
|
|
200
|
+
text: '<i class="ki-outline ki-black-right"></i>',
|
|
201
|
+
},
|
|
202
|
+
more: {
|
|
203
|
+
/**
|
|
204
|
+
* CSS classes to be added to the pagination more button
|
|
205
|
+
*/
|
|
206
|
+
class: 'btn',
|
|
207
|
+
/**
|
|
208
|
+
* Text to be displayed in the pagination more button
|
|
209
|
+
*/
|
|
210
|
+
text: '...',
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
/**
|
|
214
|
+
* Sorting options
|
|
215
|
+
*/
|
|
216
|
+
sort: {
|
|
217
|
+
/**
|
|
218
|
+
* CSS classes to be added to the sortable headers
|
|
219
|
+
*/
|
|
220
|
+
classes: {
|
|
221
|
+
base: 'sort',
|
|
222
|
+
asc: 'asc',
|
|
223
|
+
desc: 'desc',
|
|
224
|
+
},
|
|
225
|
+
/**
|
|
226
|
+
* Local sorting callback function
|
|
227
|
+
* Sorts the data array based on the sort field and order
|
|
228
|
+
* @param data Data array to be sorted
|
|
229
|
+
* @param sortField Property name of the data object to be sorted by
|
|
230
|
+
* @param sortOrder Sorting order (ascending or descending)
|
|
231
|
+
* @returns Sorted data array
|
|
232
|
+
*/
|
|
233
|
+
callback: function (data, sortField, sortOrder) {
|
|
234
|
+
/**
|
|
235
|
+
* Compares two values by converting them to strings and removing any HTML tags or white spaces
|
|
236
|
+
* @param a First value to be compared
|
|
237
|
+
* @param b Second value to be compared
|
|
238
|
+
* @returns 1 if a > b, -1 if a < b, 0 if a === b
|
|
239
|
+
*/
|
|
240
|
+
var compareValues = function (a, b) {
|
|
241
|
+
var aText = String(a).replace(/<[^>]*>| /g, '');
|
|
242
|
+
var bText = String(b).replace(/<[^>]*>| /g, '');
|
|
243
|
+
return aText > bText ? (sortOrder === 'asc' ? 1 : -1) : (aText < bText ? (sortOrder === 'asc' ? -1 : 1) : 0);
|
|
244
|
+
};
|
|
245
|
+
return data.sort(function (a, b) {
|
|
246
|
+
var aValue = a[sortField];
|
|
247
|
+
var bValue = b[sortField];
|
|
248
|
+
return compareValues(aValue, bValue);
|
|
249
|
+
});
|
|
250
|
+
},
|
|
251
|
+
}, search: {
|
|
252
|
+
/**
|
|
253
|
+
* Delay in milliseconds before the search function is applied to the data array
|
|
254
|
+
* @default 500
|
|
255
|
+
*/
|
|
256
|
+
delay: 500, // ms
|
|
257
|
+
/**
|
|
258
|
+
* Local search callback function
|
|
259
|
+
* Filters the data array based on the search string
|
|
260
|
+
* @param data Data array to be filtered
|
|
261
|
+
* @param search Search string used to filter the data array
|
|
262
|
+
* @returns Filtered data array
|
|
263
|
+
*/
|
|
264
|
+
callback: function (data, search) {
|
|
265
|
+
if (!data || !search) {
|
|
266
|
+
return [];
|
|
267
|
+
}
|
|
268
|
+
return data.filter(function (item) {
|
|
269
|
+
if (!item) {
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
return Object.values(item).some(function (value) {
|
|
273
|
+
if (typeof value !== 'string' && typeof value !== 'number' && typeof value !== 'boolean') {
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
var valueText = String(value).replace(/<[^>]*>| /g, '').toLowerCase();
|
|
277
|
+
return valueText.includes(search.toLowerCase());
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
},
|
|
282
|
+
/**
|
|
283
|
+
* Loading spinner options
|
|
284
|
+
*/
|
|
285
|
+
loading: {
|
|
286
|
+
/**
|
|
287
|
+
* Template to be displayed during data fetching process
|
|
288
|
+
*/
|
|
289
|
+
template: "\n\t\t\t\t\t<div class=\"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2\">\n\t\t\t\t\t\t<div class=\"flex items-center gap-2 px-4 py-2 font-medium leading-none text-2sm border border-gray-200 shadow-default rounded-md text-gray-500 bg-light\">\n\t\t\t\t\t\t\t<svg class=\"animate-spin -ml-1 h-5 w-5 text-gray-600\" xmlns=\"http://www.w3.org/2000/svg\" fill=\"none\" viewBox=\"0 0 24 24\">\n\t\t\t\t\t\t\t\t<circle class=\"opacity-25\" cx=\"12\" cy=\"12\" r=\"10\" stroke=\"currentColor\" stroke-width=\"3\"></circle>\n\t\t\t\t\t\t\t\t<path class=\"opacity-75\" fill=\"currentColor\" d=\"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z\"></path>\n\t\t\t\t\t\t\t</svg>\n\t\t\t\t\t\t\t{content}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t",
|
|
290
|
+
/**
|
|
291
|
+
* Loading text to be displayed in the template
|
|
292
|
+
*/
|
|
293
|
+
content: 'Loading...'
|
|
294
|
+
},
|
|
295
|
+
/**
|
|
296
|
+
* Selectors of the elements to be targeted
|
|
297
|
+
*/
|
|
298
|
+
attributes: {
|
|
299
|
+
/**
|
|
300
|
+
* Data table element
|
|
301
|
+
*/
|
|
302
|
+
table: 'table[data-datatable-table="true"]',
|
|
303
|
+
/**
|
|
304
|
+
* Pagination info element
|
|
305
|
+
*/
|
|
306
|
+
info: '[data-datatable-info="true"]',
|
|
307
|
+
/**
|
|
308
|
+
* Page size dropdown element
|
|
309
|
+
*/
|
|
310
|
+
size: '[data-datatable-size="true"]',
|
|
311
|
+
/**
|
|
312
|
+
* Pagination element
|
|
313
|
+
*/
|
|
314
|
+
pagination: '[data-datatable-pagination="true"]',
|
|
315
|
+
/**
|
|
316
|
+
* Spinner element
|
|
317
|
+
*/
|
|
318
|
+
spinner: '[data-datatable-spinner="true"]',
|
|
319
|
+
/**
|
|
320
|
+
* Checkbox element
|
|
321
|
+
*/
|
|
322
|
+
check: '[data-datatable-check="true"]',
|
|
323
|
+
checkbox: '[data-datatable-row-check="true"]'
|
|
324
|
+
},
|
|
325
|
+
/**
|
|
326
|
+
* Enable or disable state saving
|
|
327
|
+
*/
|
|
328
|
+
stateSave: true, checkbox: {
|
|
329
|
+
checkedClass: 'checked'
|
|
330
|
+
},
|
|
331
|
+
/**
|
|
332
|
+
* Private properties
|
|
333
|
+
*/
|
|
334
|
+
_state: {} }, config);
|
|
335
|
+
};
|
|
336
|
+
/**
|
|
337
|
+
* Initialize table, tbody, thead, info, size, and pagination elements
|
|
338
|
+
* @returns {void}
|
|
339
|
+
*/
|
|
340
|
+
KTDataTable.prototype._initElements = function () {
|
|
341
|
+
/**
|
|
342
|
+
* Data table element
|
|
343
|
+
*/
|
|
344
|
+
this._tableElement = this._element.querySelector(this._config.attributes.table);
|
|
345
|
+
/**
|
|
346
|
+
* Table body element
|
|
347
|
+
*/
|
|
348
|
+
this._tbodyElement = this._tableElement.tBodies[0] || this._tableElement.createTBody();
|
|
349
|
+
/**
|
|
350
|
+
* Table head element
|
|
351
|
+
*/
|
|
352
|
+
this._theadElement = this._tableElement.tHead;
|
|
353
|
+
/**
|
|
354
|
+
* Pagination info element
|
|
355
|
+
*/
|
|
356
|
+
this._infoElement = this._element.querySelector(this._config.attributes.info);
|
|
357
|
+
/**
|
|
358
|
+
* Page size dropdown element
|
|
359
|
+
*/
|
|
360
|
+
this._sizeElement = this._element.querySelector(this._config.attributes.size);
|
|
361
|
+
/**
|
|
362
|
+
* Pagination element
|
|
363
|
+
*/
|
|
364
|
+
this._paginationElement = this._element.querySelector(this._config.attributes.pagination);
|
|
365
|
+
};
|
|
366
|
+
/**
|
|
367
|
+
* Fetch data from the server or from the DOM if `apiEndpoint` is not defined.
|
|
368
|
+
* @returns {Promise<void>} Promise which is resolved after data has been fetched and checkbox plugin initialized.
|
|
369
|
+
*/
|
|
370
|
+
KTDataTable.prototype._updateData = function () {
|
|
371
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
372
|
+
return __generator(this, function (_a) {
|
|
373
|
+
this._showSpinner(); // Show spinner before fetching data
|
|
374
|
+
// Fetch data from the DOM and initialize the checkbox plugin
|
|
375
|
+
return [2 /*return*/, (typeof this._config.apiEndpoint === 'undefined')
|
|
376
|
+
? this._fetchDataFromLocal().then(this._finalize.bind(this))
|
|
377
|
+
: this._fetchDataFromServer().then(this._finalize.bind(this))];
|
|
378
|
+
});
|
|
379
|
+
});
|
|
380
|
+
};
|
|
381
|
+
/**
|
|
382
|
+
* Finalize data table after data has been fetched
|
|
383
|
+
* @returns {void}
|
|
384
|
+
*/
|
|
385
|
+
KTDataTable.prototype._finalize = function () {
|
|
386
|
+
this._element.classList.add('datatable-initialized');
|
|
387
|
+
var headerCheckElement = this._element.querySelector(this._config.attributes.check);
|
|
388
|
+
if (headerCheckElement) {
|
|
389
|
+
this._initChecbox(headerCheckElement);
|
|
390
|
+
}
|
|
391
|
+
this._attachSearchEvent();
|
|
392
|
+
if (typeof KTComponents !== "undefined") {
|
|
393
|
+
KTComponents.init();
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Hide spinner
|
|
397
|
+
*/
|
|
398
|
+
this._hideSpinner();
|
|
399
|
+
};
|
|
400
|
+
/**
|
|
401
|
+
* Attach search event to the search input element
|
|
402
|
+
* @returns {void}
|
|
403
|
+
*/
|
|
404
|
+
KTDataTable.prototype._attachSearchEvent = function () {
|
|
405
|
+
var _this = this;
|
|
406
|
+
var tableId = this._tableId();
|
|
407
|
+
var searchElement = document.querySelector("[data-datatable-search=\"#".concat(tableId, "\"]"));
|
|
408
|
+
if (searchElement) {
|
|
409
|
+
// Check if a debounced search function already exists
|
|
410
|
+
if (searchElement._debouncedSearch) {
|
|
411
|
+
// Remove the existing debounced event listener
|
|
412
|
+
searchElement.removeEventListener('keyup', searchElement._debouncedSearch);
|
|
413
|
+
}
|
|
414
|
+
// Create a new debounced search function
|
|
415
|
+
var debouncedSearch = this._debounce(function () {
|
|
416
|
+
_this.search(searchElement.value);
|
|
417
|
+
}, this._config.search.delay);
|
|
418
|
+
// Store the new debounced function as a property of the element
|
|
419
|
+
searchElement._debouncedSearch = debouncedSearch;
|
|
420
|
+
// Add the new debounced event listener
|
|
421
|
+
searchElement.addEventListener('keyup', debouncedSearch);
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
/**
|
|
425
|
+
* Initialize the checkbox plugin
|
|
426
|
+
* @param {HTMLInputElement} headerCheckElement - The header checkbox element
|
|
427
|
+
* @returns {void}
|
|
428
|
+
*/
|
|
429
|
+
KTDataTable.prototype._initChecbox = function (headerCheckElement) {
|
|
430
|
+
this._headerCheckElement = headerCheckElement;
|
|
431
|
+
this._headerChecked = headerCheckElement.checked;
|
|
432
|
+
this._targetElements = this._element.querySelectorAll(this._config.attributes.checkbox);
|
|
433
|
+
this._checkboxHandler();
|
|
434
|
+
};
|
|
435
|
+
/**
|
|
436
|
+
* Fetch data from the DOM
|
|
437
|
+
* Fetch data from the table element and save it to the `originalData` state property.
|
|
438
|
+
* This method is used when the data is not fetched from the server via an API endpoint.
|
|
439
|
+
*/
|
|
440
|
+
KTDataTable.prototype._fetchDataFromLocal = function () {
|
|
441
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
442
|
+
var _a, sortField, sortOrder, page, pageSize, search, originalData, _b, originalData_1, originalDataAttributes, _temp, startIndex, endIndex;
|
|
443
|
+
var _c;
|
|
444
|
+
return __generator(this, function (_d) {
|
|
445
|
+
switch (_d.label) {
|
|
446
|
+
case 0:
|
|
447
|
+
_a = this.getState(), sortField = _a.sortField, sortOrder = _a.sortOrder, page = _a.page, pageSize = _a.pageSize, search = _a.search;
|
|
448
|
+
originalData = this.getState().originalData;
|
|
449
|
+
// If the table element or the original data is not defined, bail
|
|
450
|
+
if (!this._tableElement || originalData === undefined || this._tableConfigInvalidate() || this._localTableHeaderInvalidate() || this._localTableContentInvalidate()) {
|
|
451
|
+
this._deleteState();
|
|
452
|
+
_b = this._localExtractTableContent(), originalData_1 = _b.originalData, originalDataAttributes = _b.originalDataAttributes;
|
|
453
|
+
this._config._state.originalData = originalData_1;
|
|
454
|
+
this._config._state.originalDataAttributes = originalDataAttributes;
|
|
455
|
+
}
|
|
456
|
+
// Update the original data variable
|
|
457
|
+
originalData = this.getState().originalData;
|
|
458
|
+
_temp = this._data = __spreadArray([], originalData, true);
|
|
459
|
+
if (search) {
|
|
460
|
+
_temp = this._data = this._config.search.callback.call(this, this._data, search);
|
|
461
|
+
}
|
|
462
|
+
// If sorting is defined, sort the data
|
|
463
|
+
if (sortField !== undefined && sortOrder !== undefined && sortOrder !== '') {
|
|
464
|
+
if (typeof this._config.sort.callback === 'function') {
|
|
465
|
+
this._data = this._config.sort.callback.call(this, this._data, sortField, sortOrder);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
// If there is data, slice it to the current page size
|
|
469
|
+
if (((_c = this._data) === null || _c === void 0 ? void 0 : _c.length) > 0) {
|
|
470
|
+
startIndex = (page - 1) * pageSize;
|
|
471
|
+
endIndex = startIndex + pageSize;
|
|
472
|
+
this._data = this._data.slice(startIndex, endIndex);
|
|
473
|
+
}
|
|
474
|
+
// Determine number of total rows
|
|
475
|
+
this._config._state.totalItems = _temp.length;
|
|
476
|
+
// Draw the data
|
|
477
|
+
return [4 /*yield*/, this._draw()];
|
|
478
|
+
case 1:
|
|
479
|
+
// Draw the data
|
|
480
|
+
_d.sent();
|
|
481
|
+
return [2 /*return*/];
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
});
|
|
485
|
+
};
|
|
486
|
+
/**
|
|
487
|
+
* Checks if the table content has been invalidated by comparing the current checksum of the table body
|
|
488
|
+
* with the stored checksum in the state. If the checksums are different, the state is updated with the
|
|
489
|
+
* new checksum and `true` is returned. Otherwise, `false` is returned.
|
|
490
|
+
*
|
|
491
|
+
* @returns {boolean} `true` if the table content has been invalidated, `false` otherwise.
|
|
492
|
+
*/
|
|
493
|
+
KTDataTable.prototype._localTableContentInvalidate = function () {
|
|
494
|
+
var checksum = KTUtils.checksum(JSON.stringify(this._tbodyElement.innerHTML));
|
|
495
|
+
if (this.getState()._contentChecksum !== checksum) {
|
|
496
|
+
this._config._state._contentChecksum = checksum;
|
|
497
|
+
return true;
|
|
498
|
+
}
|
|
499
|
+
return false;
|
|
500
|
+
};
|
|
501
|
+
KTDataTable.prototype._tableConfigInvalidate = function () {
|
|
502
|
+
// Remove _data and _state from config
|
|
503
|
+
var _a = this._config, _data = _a._data, _state = _a._state, restConfig = __rest(_a, ["_data", "_state"]);
|
|
504
|
+
var checksum = KTUtils.checksum(JSON.stringify(restConfig));
|
|
505
|
+
if (_state._configChecksum !== checksum) {
|
|
506
|
+
this._config._state._configChecksum = checksum;
|
|
507
|
+
return true;
|
|
508
|
+
}
|
|
509
|
+
return false;
|
|
510
|
+
};
|
|
511
|
+
/**
|
|
512
|
+
* Extracts the table content and returns it as an object containing an array of original data and an array of original data attributes.
|
|
513
|
+
*
|
|
514
|
+
* @returns {{originalData: T[], originalDataAttributes: KTDataTableAttributeInterface[]}} - An object containing an array of original data and an array of original data attributes.
|
|
515
|
+
*/
|
|
516
|
+
KTDataTable.prototype._localExtractTableContent = function () {
|
|
517
|
+
var originalData = [];
|
|
518
|
+
var originalDataAttributes = [];
|
|
519
|
+
var rows = this._tbodyElement.querySelectorAll('tr');
|
|
520
|
+
rows.forEach(function (row) {
|
|
521
|
+
var dataRow = {};
|
|
522
|
+
var dataRowAttribute = {};
|
|
523
|
+
// Loop through each cell in the row
|
|
524
|
+
row.querySelectorAll('td').forEach(function (td, index) {
|
|
525
|
+
var _a;
|
|
526
|
+
var attributes = {};
|
|
527
|
+
// Copy all attributes to the cell data
|
|
528
|
+
Array.from(td.attributes).forEach(function (attr) {
|
|
529
|
+
attributes[attr.name] = attr.value;
|
|
530
|
+
});
|
|
531
|
+
// Set the data for the current row and cell
|
|
532
|
+
dataRow[index] = (_a = td.innerHTML) === null || _a === void 0 ? void 0 : _a.trim();
|
|
533
|
+
dataRowAttribute[index] = attributes;
|
|
534
|
+
});
|
|
535
|
+
// If the row has any data, add it to the original data array
|
|
536
|
+
if (Object.keys(dataRow).length > 0) {
|
|
537
|
+
originalData.push(dataRow);
|
|
538
|
+
originalDataAttributes.push(dataRowAttribute);
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
|
+
return { originalData: originalData, originalDataAttributes: originalDataAttributes };
|
|
542
|
+
};
|
|
543
|
+
/**
|
|
544
|
+
* Check if the table header is invalidated
|
|
545
|
+
* @returns {boolean} - Returns true if the table header is invalidated, false otherwise
|
|
546
|
+
*/
|
|
547
|
+
KTDataTable.prototype._localTableHeaderInvalidate = function () {
|
|
548
|
+
var _a;
|
|
549
|
+
var originalData = this.getState().originalData;
|
|
550
|
+
var currentTableHeaders = ((_a = this._getTableHeaders()) === null || _a === void 0 ? void 0 : _a.length) || 0;
|
|
551
|
+
var totalColumns = originalData.length ? Object.keys(originalData[0]).length : 0;
|
|
552
|
+
return currentTableHeaders !== totalColumns;
|
|
553
|
+
};
|
|
554
|
+
/**
|
|
555
|
+
* Fetch data from the server
|
|
556
|
+
*/
|
|
557
|
+
KTDataTable.prototype._fetchDataFromServer = function () {
|
|
558
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
559
|
+
var queryParams, response, responseData, error_1;
|
|
560
|
+
return __generator(this, function (_a) {
|
|
561
|
+
switch (_a.label) {
|
|
562
|
+
case 0:
|
|
563
|
+
this._fireEvent('fetch');
|
|
564
|
+
this._dispatchEvent('fetch');
|
|
565
|
+
queryParams = this._getQueryParamsForFetchRequest();
|
|
566
|
+
return [4 /*yield*/, this._performFetchRequest(queryParams)];
|
|
567
|
+
case 1:
|
|
568
|
+
response = _a.sent();
|
|
569
|
+
responseData = null;
|
|
570
|
+
_a.label = 2;
|
|
571
|
+
case 2:
|
|
572
|
+
_a.trys.push([2, 4, , 5]);
|
|
573
|
+
return [4 /*yield*/, response.json()];
|
|
574
|
+
case 3:
|
|
575
|
+
responseData = _a.sent();
|
|
576
|
+
return [3 /*break*/, 5];
|
|
577
|
+
case 4:
|
|
578
|
+
error_1 = _a.sent();
|
|
579
|
+
this._noticeOnTable('Error parsing API response as JSON: ' + String(error_1));
|
|
580
|
+
return [2 /*return*/];
|
|
581
|
+
case 5:
|
|
582
|
+
this._fireEvent('fetched', { response: responseData });
|
|
583
|
+
this._dispatchEvent('fetched', { response: responseData });
|
|
584
|
+
// Use the mapResponse function to transform the data if provided
|
|
585
|
+
if (typeof this._config.mapResponse === 'function') {
|
|
586
|
+
responseData = this._config.mapResponse.call(this, responseData);
|
|
587
|
+
}
|
|
588
|
+
this._data = responseData.data;
|
|
589
|
+
this._config._state.totalItems = responseData.totalCount;
|
|
590
|
+
return [4 /*yield*/, this._draw()];
|
|
591
|
+
case 6:
|
|
592
|
+
_a.sent();
|
|
593
|
+
return [2 /*return*/];
|
|
594
|
+
}
|
|
595
|
+
});
|
|
596
|
+
});
|
|
597
|
+
};
|
|
598
|
+
/**
|
|
599
|
+
* Get the query params for a fetch request
|
|
600
|
+
* @returns The query params for the fetch request
|
|
601
|
+
*/
|
|
602
|
+
KTDataTable.prototype._getQueryParamsForFetchRequest = function () {
|
|
603
|
+
// Get the current state of the datatable
|
|
604
|
+
var _a = this.getState(), page = _a.page, pageSize = _a.pageSize, sortField = _a.sortField, sortOrder = _a.sortOrder, filters = _a.filters, search = _a.search;
|
|
605
|
+
// Create a new URLSearchParams object to store the query params
|
|
606
|
+
var queryParams = new URLSearchParams();
|
|
607
|
+
// Add the current page number and page size to the query params
|
|
608
|
+
queryParams.set('page', String(page));
|
|
609
|
+
queryParams.set('size', String(pageSize));
|
|
610
|
+
// If there is a sort order and field set, add them to the query params
|
|
611
|
+
if (sortOrder !== undefined) {
|
|
612
|
+
queryParams.set('sortOrder', String(sortOrder));
|
|
613
|
+
}
|
|
614
|
+
if (sortField !== undefined) {
|
|
615
|
+
queryParams.set('sortField', String(sortField));
|
|
616
|
+
}
|
|
617
|
+
// If there are any filters set, add them to the query params
|
|
618
|
+
if (Array.isArray(filters) && filters.length) {
|
|
619
|
+
queryParams.set('filters', JSON.stringify(filters.map(function (filter) { return ({
|
|
620
|
+
// Map the filter object to a simpler object with just the necessary properties
|
|
621
|
+
column: filter.column,
|
|
622
|
+
type: filter.type,
|
|
623
|
+
value: filter.value,
|
|
624
|
+
}); })));
|
|
625
|
+
}
|
|
626
|
+
if (search) {
|
|
627
|
+
queryParams.set('search', typeof search === 'object' ? JSON.stringify(search) : search);
|
|
628
|
+
}
|
|
629
|
+
// If a mapRequest function is provided, call it with the query params object
|
|
630
|
+
if (typeof this._config.mapRequest === 'function') {
|
|
631
|
+
queryParams = this._config.mapRequest.call(this, queryParams);
|
|
632
|
+
}
|
|
633
|
+
// Return the query params object
|
|
634
|
+
return queryParams;
|
|
635
|
+
};
|
|
636
|
+
KTDataTable.prototype._performFetchRequest = function (queryParams) {
|
|
637
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
638
|
+
var requestMethod, requestBody, apiEndpointWithQueryParams;
|
|
639
|
+
var _this = this;
|
|
640
|
+
return __generator(this, function (_a) {
|
|
641
|
+
requestMethod = this._config.requestMethod;
|
|
642
|
+
requestBody = undefined;
|
|
643
|
+
// If the request method is POST, send the query params as the request body
|
|
644
|
+
if (requestMethod === 'POST') {
|
|
645
|
+
requestBody = queryParams;
|
|
646
|
+
}
|
|
647
|
+
else if (requestMethod === 'GET') {
|
|
648
|
+
apiEndpointWithQueryParams = new URL(this._config.apiEndpoint);
|
|
649
|
+
apiEndpointWithQueryParams.search = queryParams.toString();
|
|
650
|
+
this._config.apiEndpoint = apiEndpointWithQueryParams.toString();
|
|
651
|
+
}
|
|
652
|
+
return [2 /*return*/, fetch(this._config.apiEndpoint, {
|
|
653
|
+
method: requestMethod,
|
|
654
|
+
body: requestBody,
|
|
655
|
+
headers: this._config.requestHeaders
|
|
656
|
+
}).catch(function (error) {
|
|
657
|
+
_this._noticeOnTable('Error performing fetch request: ' + String(error));
|
|
658
|
+
throw error;
|
|
659
|
+
})];
|
|
660
|
+
});
|
|
661
|
+
});
|
|
662
|
+
};
|
|
663
|
+
/**
|
|
664
|
+
* Update the table and pagination controls with new data
|
|
665
|
+
* @returns {Promise<void>} A promise that resolves when the table and pagination controls are updated
|
|
666
|
+
*/
|
|
667
|
+
KTDataTable.prototype._draw = function () {
|
|
668
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
669
|
+
return __generator(this, function (_a) {
|
|
670
|
+
this._config._state.totalPages = Math.ceil(this.getState().totalItems / this.getState().pageSize) || 0;
|
|
671
|
+
this._fireEvent('draw');
|
|
672
|
+
this._dispatchEvent('draw');
|
|
673
|
+
this._dispose();
|
|
674
|
+
// Update the table and pagination controls
|
|
675
|
+
if (this._theadElement && this._tbodyElement) {
|
|
676
|
+
this._updateTable();
|
|
677
|
+
}
|
|
678
|
+
if (this._infoElement && this._paginationElement) {
|
|
679
|
+
this._updatePagination();
|
|
680
|
+
}
|
|
681
|
+
this._fireEvent('drew');
|
|
682
|
+
this._dispatchEvent('drew');
|
|
683
|
+
this._hideSpinner(); // Hide spinner after data is fetched
|
|
684
|
+
if (this._config.stateSave) {
|
|
685
|
+
this._saveState();
|
|
686
|
+
}
|
|
687
|
+
return [2 /*return*/];
|
|
688
|
+
});
|
|
689
|
+
});
|
|
690
|
+
};
|
|
691
|
+
/**
|
|
692
|
+
* Update the HTML table with new data
|
|
693
|
+
* @returns {HTMLTableSectionElement} The new table body element
|
|
694
|
+
*/
|
|
695
|
+
KTDataTable.prototype._updateTable = function () {
|
|
696
|
+
// Clear the existing table contents using a more efficient method
|
|
697
|
+
while (this._tableElement.tBodies.length) {
|
|
698
|
+
this._tableElement.removeChild(this._tableElement.tBodies[0]);
|
|
699
|
+
}
|
|
700
|
+
// Create the table body with the new data
|
|
701
|
+
var tbodyElement = this._tableElement.createTBody();
|
|
702
|
+
this._updateTableContent(tbodyElement);
|
|
703
|
+
return tbodyElement;
|
|
704
|
+
};
|
|
705
|
+
/**
|
|
706
|
+
* Initialize the table header
|
|
707
|
+
* Add sort event listener to all sortable columns
|
|
708
|
+
*/
|
|
709
|
+
KTDataTable.prototype._initTableHeader = function () {
|
|
710
|
+
var _this = this;
|
|
711
|
+
if (!this._theadElement) {
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
// Set the initial sort icon
|
|
715
|
+
this._setSortIcon(this.getState().sortField, this.getState().sortOrder);
|
|
716
|
+
// Get all the table headers
|
|
717
|
+
var headers = this._getTableHeaders();
|
|
718
|
+
// Loop through each table header
|
|
719
|
+
headers.forEach(function (header) {
|
|
720
|
+
// If the sort class is not found, it's not a sortable column
|
|
721
|
+
if (!header.querySelector(".".concat(_this._config.sort.classes.base))) {
|
|
722
|
+
return;
|
|
723
|
+
}
|
|
724
|
+
var sortAttribute = header.getAttribute('data-datatable-column-sort') || header.getAttribute('data-datatable-column');
|
|
725
|
+
var sortField = sortAttribute ? sortAttribute : header.cellIndex;
|
|
726
|
+
// Add click event listener to the header
|
|
727
|
+
header.addEventListener('click', function () {
|
|
728
|
+
var sortOrder = _this._toggleSortOrder(sortField);
|
|
729
|
+
_this._setSortIcon(sortField, sortOrder);
|
|
730
|
+
_this._sort(sortField);
|
|
731
|
+
});
|
|
732
|
+
});
|
|
733
|
+
};
|
|
734
|
+
/**
|
|
735
|
+
* Returns an array of table headers as HTMLTableCellElement.
|
|
736
|
+
* @returns {HTMLTableCellElement[]} An array of table headers.
|
|
737
|
+
*/
|
|
738
|
+
KTDataTable.prototype._getTableHeaders = function () {
|
|
739
|
+
if (!this._theadElement) {
|
|
740
|
+
return [];
|
|
741
|
+
}
|
|
742
|
+
return Array.from(this._theadElement.querySelectorAll('th'));
|
|
743
|
+
};
|
|
744
|
+
/**
|
|
745
|
+
* Sets the sort icon in the table header
|
|
746
|
+
* @param sortField The field to set the sort icon for
|
|
747
|
+
* @param sortOrder The sort order (ascending or descending)
|
|
748
|
+
*/
|
|
749
|
+
KTDataTable.prototype._setSortIcon = function (sortField, sortOrder) {
|
|
750
|
+
var sortClass = sortOrder ? (sortOrder === 'asc' ? this._config.sort.classes.asc : this._config.sort.classes.desc) : '';
|
|
751
|
+
// Get the appropriate table header element
|
|
752
|
+
var th = typeof sortField === 'number'
|
|
753
|
+
? this._theadElement.querySelectorAll('th')[sortField]
|
|
754
|
+
: this._theadElement.querySelector("th[data-datatable-column=\"".concat(String(sortField), "\"], th[data-datatable-column-sort=\"").concat(String(sortField), "\"]"));
|
|
755
|
+
if (th) {
|
|
756
|
+
var sortElement = th.querySelector(".".concat(this._config.sort.classes.base));
|
|
757
|
+
if (sortElement) {
|
|
758
|
+
sortElement.className = "".concat(this._config.sort.classes.base, " ").concat(sortClass).trim();
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
};
|
|
762
|
+
/**
|
|
763
|
+
* Toggles the sort order of a column
|
|
764
|
+
* @param sortField The field to toggle the sort order for
|
|
765
|
+
* @returns The new sort order (ascending, descending or unsorted)
|
|
766
|
+
*/
|
|
767
|
+
KTDataTable.prototype._toggleSortOrder = function (sortField) {
|
|
768
|
+
var _this = this;
|
|
769
|
+
// If the sort field is the same as the current sort field,
|
|
770
|
+
// toggle the sort order. Otherwise, set the sort order to ascending.
|
|
771
|
+
return (function () {
|
|
772
|
+
if (_this.getState().sortField === sortField) {
|
|
773
|
+
switch (_this.getState().sortOrder) {
|
|
774
|
+
case 'asc':
|
|
775
|
+
return 'desc'; // Descending
|
|
776
|
+
case 'desc':
|
|
777
|
+
return ''; // Unsorted
|
|
778
|
+
default:
|
|
779
|
+
return 'asc'; // Ascending
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
return 'asc'; // Ascending
|
|
783
|
+
})();
|
|
784
|
+
};
|
|
785
|
+
/**
|
|
786
|
+
* Update the table content
|
|
787
|
+
* @param tbodyElement The table body element
|
|
788
|
+
* @returns {HTMLTableSectionElement} The updated table body element
|
|
789
|
+
*/
|
|
790
|
+
KTDataTable.prototype._updateTableContent = function (tbodyElement) {
|
|
791
|
+
var _this = this;
|
|
792
|
+
var fragment = document.createDocumentFragment();
|
|
793
|
+
tbodyElement.textContent = ''; // Clear the tbody element
|
|
794
|
+
if (this._data.length === 0) {
|
|
795
|
+
this._noticeOnTable(this._config.infoEmpty || '');
|
|
796
|
+
return tbodyElement;
|
|
797
|
+
}
|
|
798
|
+
this._data.forEach(function (item, rowIndex) {
|
|
799
|
+
var row = document.createElement('tr');
|
|
800
|
+
if (!_this._config.columns) {
|
|
801
|
+
var dataRowAttributes_1 = _this.getState().originalDataAttributes
|
|
802
|
+
? _this.getState().originalDataAttributes[rowIndex]
|
|
803
|
+
: null;
|
|
804
|
+
Object.keys(item).forEach(function (key, colIndex) {
|
|
805
|
+
var td = document.createElement('td');
|
|
806
|
+
td.innerHTML = item[key];
|
|
807
|
+
if (dataRowAttributes_1) {
|
|
808
|
+
for (var attr in dataRowAttributes_1[colIndex]) {
|
|
809
|
+
td.setAttribute(attr, dataRowAttributes_1[colIndex][attr]);
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
row.appendChild(td);
|
|
813
|
+
});
|
|
814
|
+
}
|
|
815
|
+
else {
|
|
816
|
+
Object.keys(_this._config.columns).forEach(function (key) {
|
|
817
|
+
var td = document.createElement('td');
|
|
818
|
+
var columnDef = _this._config.columns[key];
|
|
819
|
+
if (typeof columnDef.render === 'function') {
|
|
820
|
+
td.innerHTML = columnDef.render.call(_this, item[key], item, _this);
|
|
821
|
+
}
|
|
822
|
+
else {
|
|
823
|
+
td.textContent = item[key];
|
|
824
|
+
}
|
|
825
|
+
if (typeof columnDef.createdCell === 'function') {
|
|
826
|
+
columnDef.createdCell.call(_this, td, item[key], item, row);
|
|
827
|
+
}
|
|
828
|
+
row.appendChild(td);
|
|
829
|
+
});
|
|
830
|
+
}
|
|
831
|
+
fragment.appendChild(row);
|
|
832
|
+
});
|
|
833
|
+
tbodyElement.appendChild(fragment);
|
|
834
|
+
return tbodyElement;
|
|
835
|
+
};
|
|
836
|
+
/**
|
|
837
|
+
* Show a notice on the table
|
|
838
|
+
* @param message The message to show. If empty, the message will be removed
|
|
839
|
+
* @returns {void}
|
|
840
|
+
*/
|
|
841
|
+
KTDataTable.prototype._noticeOnTable = function (message) {
|
|
842
|
+
var _a;
|
|
843
|
+
if (message === void 0) { message = ''; }
|
|
844
|
+
var row = this._tbodyElement.insertRow();
|
|
845
|
+
var cell = row.insertCell();
|
|
846
|
+
cell.colSpan = ((_a = this._getTableHeaders()) === null || _a === void 0 ? void 0 : _a.length) || 0;
|
|
847
|
+
cell.innerHTML = message;
|
|
848
|
+
};
|
|
849
|
+
KTDataTable.prototype._updatePagination = function () {
|
|
850
|
+
this._removeChildElements(this._sizeElement);
|
|
851
|
+
this._createPageSizeControls(this._sizeElement);
|
|
852
|
+
this._removeChildElements(this._paginationElement);
|
|
853
|
+
this._createPaginationControls(this._infoElement, this._paginationElement);
|
|
854
|
+
};
|
|
855
|
+
/**
|
|
856
|
+
* Removes all child elements from the given container element.
|
|
857
|
+
* @param container The container element to remove the child elements from.
|
|
858
|
+
*/
|
|
859
|
+
KTDataTable.prototype._removeChildElements = function (container) {
|
|
860
|
+
if (!container) {
|
|
861
|
+
return;
|
|
862
|
+
}
|
|
863
|
+
// Loop through all child elements of the container and remove them one by one
|
|
864
|
+
while (container.firstChild) {
|
|
865
|
+
// Remove the first child element (which is the first element in the list of child elements)
|
|
866
|
+
container.removeChild(container.firstChild);
|
|
867
|
+
}
|
|
868
|
+
};
|
|
869
|
+
/**
|
|
870
|
+
* Creates a container element for the items per page selector.
|
|
871
|
+
* @param _sizeElement The element to create the page size controls in.
|
|
872
|
+
* @returns The container element.
|
|
873
|
+
*/
|
|
874
|
+
KTDataTable.prototype._createPageSizeControls = function (_sizeElement) {
|
|
875
|
+
var _this = this;
|
|
876
|
+
// If no element is provided, return early
|
|
877
|
+
if (!_sizeElement) {
|
|
878
|
+
return _sizeElement;
|
|
879
|
+
}
|
|
880
|
+
// Create <option> elements for each page size option
|
|
881
|
+
var options = this._config.pageSizes.map(function (size) {
|
|
882
|
+
var option = document.createElement('option');
|
|
883
|
+
option.value = String(size);
|
|
884
|
+
option.text = String(size);
|
|
885
|
+
option.selected = _this.getState().pageSize === size;
|
|
886
|
+
return option;
|
|
887
|
+
});
|
|
888
|
+
// Add the <option> elements to the provided element
|
|
889
|
+
_sizeElement.append.apply(_sizeElement, options);
|
|
890
|
+
// Create an event listener for the "change" event on the element
|
|
891
|
+
var _pageSizeControlsEvent = function (event) {
|
|
892
|
+
// When the element changes, reload the page with the new page size and page number 1
|
|
893
|
+
_this._reloadPageSize(Number(event.target.value), 1);
|
|
894
|
+
};
|
|
895
|
+
// Bind the event listener to the component instance
|
|
896
|
+
_sizeElement.onchange = _pageSizeControlsEvent.bind(this);
|
|
897
|
+
// Return the element
|
|
898
|
+
return _sizeElement;
|
|
899
|
+
};
|
|
900
|
+
/**
|
|
901
|
+
* Reloads the data with the specified page size and optional page number.
|
|
902
|
+
* @param pageSize The new page size.
|
|
903
|
+
* @param page The new page number (optional, defaults to 1).
|
|
904
|
+
*/
|
|
905
|
+
KTDataTable.prototype._reloadPageSize = function (pageSize, page) {
|
|
906
|
+
if (page === void 0) { page = 1; }
|
|
907
|
+
// Update the page size and page number in the state
|
|
908
|
+
this._config._state.pageSize = pageSize;
|
|
909
|
+
this._config._state.page = page;
|
|
910
|
+
// Update the data with the new page size and page number
|
|
911
|
+
this._updateData();
|
|
912
|
+
};
|
|
913
|
+
/**
|
|
914
|
+
* Creates the pagination controls for the component.
|
|
915
|
+
* @param _infoElement The element to set the info text in.
|
|
916
|
+
* @param _paginationElement The element to create the pagination controls in.
|
|
917
|
+
* @return {HTMLElement} The element containing the pagination controls.
|
|
918
|
+
*/
|
|
919
|
+
KTDataTable.prototype._createPaginationControls = function (_infoElement, _paginationElement) {
|
|
920
|
+
if (!_infoElement || !_paginationElement || this._data.length === 0) {
|
|
921
|
+
return null;
|
|
922
|
+
}
|
|
923
|
+
this._setPaginationInfoText(_infoElement);
|
|
924
|
+
var paginationContainer = this._createPaginationContainer(_paginationElement);
|
|
925
|
+
if (paginationContainer) {
|
|
926
|
+
this._createPaginationButtons(paginationContainer);
|
|
927
|
+
}
|
|
928
|
+
return paginationContainer;
|
|
929
|
+
};
|
|
930
|
+
/**
|
|
931
|
+
* Sets the info text for the pagination controls.
|
|
932
|
+
* @param _infoElement The element to set the info text in.
|
|
933
|
+
*/
|
|
934
|
+
KTDataTable.prototype._setPaginationInfoText = function (_infoElement) {
|
|
935
|
+
_infoElement.textContent = this._config.info
|
|
936
|
+
.replace('{start}', (this.getState().page - 1) * this.getState().pageSize + 1 + '')
|
|
937
|
+
.replace('{end}', Math.min(this.getState().page * this.getState().pageSize, this.getState().totalItems) + '')
|
|
938
|
+
.replace('{total}', this.getState().totalItems + '');
|
|
939
|
+
};
|
|
940
|
+
/**
|
|
941
|
+
* Creates the container element for the pagination controls.
|
|
942
|
+
* @param _paginationElement The element to create the pagination controls in.
|
|
943
|
+
* @return {HTMLElement} The container element.
|
|
944
|
+
*/
|
|
945
|
+
KTDataTable.prototype._createPaginationContainer = function (_paginationElement) {
|
|
946
|
+
var paginationContainer = document.createElement('div');
|
|
947
|
+
paginationContainer.className = 'pagination';
|
|
948
|
+
_paginationElement.appendChild(paginationContainer);
|
|
949
|
+
return paginationContainer;
|
|
950
|
+
};
|
|
951
|
+
/**
|
|
952
|
+
* Creates the pagination buttons for the component.
|
|
953
|
+
* @param paginationContainer The container element for the pagination controls.
|
|
954
|
+
*/
|
|
955
|
+
KTDataTable.prototype._createPaginationButtons = function (paginationContainer) {
|
|
956
|
+
var _this = this;
|
|
957
|
+
var _a = this.getState(), currentPage = _a.page, totalPages = _a.totalPages;
|
|
958
|
+
var _b = this._config.pagination, previous = _b.previous, next = _b.next, number = _b.number, more = _b.more;
|
|
959
|
+
// Helper function to create a button
|
|
960
|
+
var createButton = function (text, className, disabled, handleClick) {
|
|
961
|
+
var button = document.createElement('button');
|
|
962
|
+
button.className = className;
|
|
963
|
+
button.innerHTML = text;
|
|
964
|
+
button.disabled = disabled;
|
|
965
|
+
button.onclick = handleClick;
|
|
966
|
+
return button;
|
|
967
|
+
};
|
|
968
|
+
// Add Previous Button
|
|
969
|
+
paginationContainer.appendChild(createButton(previous.text, "".concat(previous.class).concat(currentPage === 1 ? ' disabled' : ''), currentPage === 1, function () { return _this._paginateData(currentPage - 1); }));
|
|
970
|
+
// Calculate range of pages
|
|
971
|
+
var pageMoreEnabled = this._config.pageMore;
|
|
972
|
+
if (pageMoreEnabled) {
|
|
973
|
+
var maxButtons = this._config.pageMoreLimit;
|
|
974
|
+
var range_1 = this._calculatePageRange(currentPage, totalPages, maxButtons);
|
|
975
|
+
// Add start ellipsis
|
|
976
|
+
if (range_1.start > 1) {
|
|
977
|
+
paginationContainer.appendChild(createButton(more.text, more.class, false, function () { return _this._paginateData(Math.max(1, range_1.start - 1)); }));
|
|
978
|
+
}
|
|
979
|
+
var _loop_1 = function (i) {
|
|
980
|
+
paginationContainer.appendChild(createButton(number.text.replace('{page}', i.toString()), "".concat(number.class).concat(currentPage === i ? ' active disabled' : ''), currentPage === i, function () { return _this._paginateData(i); }));
|
|
981
|
+
};
|
|
982
|
+
// Add page buttons
|
|
983
|
+
for (var i = range_1.start; i <= range_1.end; i++) {
|
|
984
|
+
_loop_1(i);
|
|
985
|
+
}
|
|
986
|
+
// Add end ellipsis
|
|
987
|
+
if (pageMoreEnabled && range_1.end < totalPages) {
|
|
988
|
+
paginationContainer.appendChild(createButton(more.text, more.class, false, function () { return _this._paginateData(Math.min(totalPages, range_1.end + 1)); }));
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
else {
|
|
992
|
+
var _loop_2 = function (i) {
|
|
993
|
+
paginationContainer.appendChild(createButton(number.text.replace('{page}', i.toString()), "".concat(number.class).concat(currentPage === i ? ' active disabled' : ''), currentPage === i, function () { return _this._paginateData(i); }));
|
|
994
|
+
};
|
|
995
|
+
// Add page buttons
|
|
996
|
+
for (var i = 1; i <= totalPages; i++) {
|
|
997
|
+
_loop_2(i);
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
// Add Next Button
|
|
1001
|
+
paginationContainer.appendChild(createButton(next.text, "".concat(next.class).concat(currentPage === totalPages ? ' disabled' : ''), currentPage === totalPages, function () { return _this._paginateData(currentPage + 1); }));
|
|
1002
|
+
};
|
|
1003
|
+
// New helper method to calculate page range
|
|
1004
|
+
KTDataTable.prototype._calculatePageRange = function (currentPage, totalPages, maxButtons) {
|
|
1005
|
+
var startPage, endPage;
|
|
1006
|
+
var halfMaxButtons = Math.floor(maxButtons / 2);
|
|
1007
|
+
if (totalPages <= maxButtons) {
|
|
1008
|
+
startPage = 1;
|
|
1009
|
+
endPage = totalPages;
|
|
1010
|
+
}
|
|
1011
|
+
else {
|
|
1012
|
+
startPage = Math.max(currentPage - halfMaxButtons, 1);
|
|
1013
|
+
endPage = Math.min(startPage + maxButtons - 1, totalPages);
|
|
1014
|
+
if (endPage - startPage < maxButtons - 1) {
|
|
1015
|
+
startPage = Math.max(endPage - maxButtons + 1, 1);
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
return { start: startPage, end: endPage };
|
|
1019
|
+
};
|
|
1020
|
+
/**
|
|
1021
|
+
* Method for handling pagination
|
|
1022
|
+
* @param page - The page number to navigate to
|
|
1023
|
+
*/
|
|
1024
|
+
KTDataTable.prototype._paginateData = function (page) {
|
|
1025
|
+
if (page < 1 || !Number.isInteger(page)) {
|
|
1026
|
+
return;
|
|
1027
|
+
}
|
|
1028
|
+
this._fireEvent('pagination', { page: page });
|
|
1029
|
+
this._dispatchEvent('pagination', { page: page });
|
|
1030
|
+
if (page >= 1 && page <= this.getState().totalPages) {
|
|
1031
|
+
this._config._state.page = page;
|
|
1032
|
+
this._updateData();
|
|
1033
|
+
}
|
|
1034
|
+
};
|
|
1035
|
+
// Method to show the loading spinner
|
|
1036
|
+
KTDataTable.prototype._showSpinner = function () {
|
|
1037
|
+
var spinner = this._element.querySelector(this._config.attributes.spinner) || this._createSpinner();
|
|
1038
|
+
if (spinner) {
|
|
1039
|
+
spinner.style.display = 'block';
|
|
1040
|
+
}
|
|
1041
|
+
this._element.classList.add('loading');
|
|
1042
|
+
};
|
|
1043
|
+
// Method to hide the loading spinner
|
|
1044
|
+
KTDataTable.prototype._hideSpinner = function () {
|
|
1045
|
+
var spinner = this._element.querySelector(this._config.attributes.spinner);
|
|
1046
|
+
if (spinner) {
|
|
1047
|
+
spinner.style.display = 'none';
|
|
1048
|
+
}
|
|
1049
|
+
this._element.classList.remove('loading');
|
|
1050
|
+
};
|
|
1051
|
+
// Method to create a spinner element if it doesn't exist
|
|
1052
|
+
KTDataTable.prototype._createSpinner = function () {
|
|
1053
|
+
if (typeof this._config.loading === 'undefined') {
|
|
1054
|
+
return null;
|
|
1055
|
+
}
|
|
1056
|
+
var template = document.createElement('template');
|
|
1057
|
+
template.innerHTML = this._config.loading.template.trim().replace('{content}', this._config.loading.content);
|
|
1058
|
+
var spinner = template.content.firstChild;
|
|
1059
|
+
spinner.setAttribute('data-datatable-spinner', 'true');
|
|
1060
|
+
this._tableElement.appendChild(spinner);
|
|
1061
|
+
return spinner;
|
|
1062
|
+
};
|
|
1063
|
+
/**
|
|
1064
|
+
* Saves the current state of the table to local storage.
|
|
1065
|
+
* @returns {void}
|
|
1066
|
+
*/
|
|
1067
|
+
KTDataTable.prototype._saveState = function () {
|
|
1068
|
+
this._fireEvent('stateSave');
|
|
1069
|
+
this._dispatchEvent('stateSave');
|
|
1070
|
+
var ns = this._tableNamespace();
|
|
1071
|
+
if (ns) {
|
|
1072
|
+
localStorage.setItem(ns, JSON.stringify(this.getState()));
|
|
1073
|
+
}
|
|
1074
|
+
};
|
|
1075
|
+
/**
|
|
1076
|
+
* Loads the saved state of the table from local storage, if it exists.
|
|
1077
|
+
* @returns {Object} The saved state of the table, or null if no saved state exists.
|
|
1078
|
+
*/
|
|
1079
|
+
KTDataTable.prototype._loadState = function () {
|
|
1080
|
+
var stateString = localStorage.getItem(this._tableNamespace());
|
|
1081
|
+
if (!stateString)
|
|
1082
|
+
return null;
|
|
1083
|
+
try {
|
|
1084
|
+
var state = JSON.parse(stateString);
|
|
1085
|
+
if (state)
|
|
1086
|
+
this._config._state = state;
|
|
1087
|
+
return state;
|
|
1088
|
+
}
|
|
1089
|
+
catch (_a) { } // eslint-disable-line no-empty
|
|
1090
|
+
return null;
|
|
1091
|
+
};
|
|
1092
|
+
KTDataTable.prototype._deleteState = function () {
|
|
1093
|
+
var ns = this._tableNamespace();
|
|
1094
|
+
if (ns) {
|
|
1095
|
+
localStorage.removeItem(ns);
|
|
1096
|
+
}
|
|
1097
|
+
};
|
|
1098
|
+
/**
|
|
1099
|
+
* Gets the namespace for the table's state.
|
|
1100
|
+
* If a namespace is specified in the config, it is used.
|
|
1101
|
+
* Otherwise, if the table element has an ID, it is used.
|
|
1102
|
+
* Otherwise, if the component element has an ID, it is used.
|
|
1103
|
+
* Finally, the component's UID is used.
|
|
1104
|
+
* @returns {string} The namespace for the table's state.
|
|
1105
|
+
*/
|
|
1106
|
+
KTDataTable.prototype._tableNamespace = function () {
|
|
1107
|
+
var _a;
|
|
1108
|
+
// Use the specified namespace, if one is given
|
|
1109
|
+
if (this._config.stateNamespace) {
|
|
1110
|
+
return this._config.stateNamespace;
|
|
1111
|
+
}
|
|
1112
|
+
// Fallback to the component's UID
|
|
1113
|
+
return (_a = this._tableId()) !== null && _a !== void 0 ? _a : this._name;
|
|
1114
|
+
};
|
|
1115
|
+
KTDataTable.prototype._tableId = function () {
|
|
1116
|
+
var _a, _b;
|
|
1117
|
+
var id = null;
|
|
1118
|
+
// If the table element has an ID, use that
|
|
1119
|
+
if ((_a = this._tableElement) === null || _a === void 0 ? void 0 : _a.getAttribute('id')) {
|
|
1120
|
+
id = this._tableElement.getAttribute('id');
|
|
1121
|
+
}
|
|
1122
|
+
// If the component element has an ID, use that
|
|
1123
|
+
if ((_b = this._element) === null || _b === void 0 ? void 0 : _b.getAttribute('id')) {
|
|
1124
|
+
id = this._element.getAttribute('id');
|
|
1125
|
+
}
|
|
1126
|
+
return id;
|
|
1127
|
+
};
|
|
1128
|
+
/**
|
|
1129
|
+
* Sorts the data in the table by the specified field.
|
|
1130
|
+
* @param sortField The field to sort by.
|
|
1131
|
+
*/
|
|
1132
|
+
KTDataTable.prototype._sort = function (sortField) {
|
|
1133
|
+
// Determine the new sort order based on the current state
|
|
1134
|
+
var newSortOrder = this._toggleSortOrder(sortField);
|
|
1135
|
+
// Update the current sort field and order
|
|
1136
|
+
this._config._state.sortField = sortField;
|
|
1137
|
+
this._config._state.sortOrder = newSortOrder;
|
|
1138
|
+
this._fireEvent('sort', { field: sortField, order: newSortOrder });
|
|
1139
|
+
this._dispatchEvent('sort', { field: sortField, order: newSortOrder });
|
|
1140
|
+
// Fetch data from the server with the new sort order
|
|
1141
|
+
this._updateData();
|
|
1142
|
+
};
|
|
1143
|
+
KTDataTable.prototype._dispose = function () {
|
|
1144
|
+
if (this._headerCheckElement) {
|
|
1145
|
+
this._headerCheckElement.removeEventListener('click', this._checkboxListener);
|
|
1146
|
+
}
|
|
1147
|
+
};
|
|
1148
|
+
KTDataTable.prototype._debounce = function (func, wait) {
|
|
1149
|
+
var timeout;
|
|
1150
|
+
return function () {
|
|
1151
|
+
var args = [];
|
|
1152
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1153
|
+
args[_i] = arguments[_i];
|
|
1154
|
+
}
|
|
1155
|
+
var later = function () {
|
|
1156
|
+
clearTimeout(timeout);
|
|
1157
|
+
func.apply(void 0, args);
|
|
1158
|
+
};
|
|
1159
|
+
clearTimeout(timeout);
|
|
1160
|
+
timeout = window.setTimeout(later, wait);
|
|
1161
|
+
};
|
|
1162
|
+
};
|
|
1163
|
+
/**
|
|
1164
|
+
* Event handlers
|
|
1165
|
+
*/
|
|
1166
|
+
KTDataTable.prototype._checkboxHandler = function () {
|
|
1167
|
+
var _this = this;
|
|
1168
|
+
// Handle header checkbox change event
|
|
1169
|
+
this._headerCheckElement.addEventListener('click', this._checkboxListener);
|
|
1170
|
+
// Handle target checbox change event
|
|
1171
|
+
KTEventHandler.on(document.body, this._config.attributes.checkbox, 'input', function (event) {
|
|
1172
|
+
_this._checkboxUpdate(event); // Update checkbox state based on checked rows
|
|
1173
|
+
});
|
|
1174
|
+
};
|
|
1175
|
+
/**
|
|
1176
|
+
* Checks if element is checked
|
|
1177
|
+
* @returns {boolean}
|
|
1178
|
+
*/
|
|
1179
|
+
KTDataTable.prototype._isChecked = function () {
|
|
1180
|
+
return this._headerChecked;
|
|
1181
|
+
};
|
|
1182
|
+
/**
|
|
1183
|
+
* Change checkbox state
|
|
1184
|
+
* @param checked The new state of the checkbox
|
|
1185
|
+
* @returns {void}
|
|
1186
|
+
*/
|
|
1187
|
+
KTDataTable.prototype._change = function (checked) {
|
|
1188
|
+
var payload = { cancel: false };
|
|
1189
|
+
this._fireEvent('change', payload);
|
|
1190
|
+
this._dispatchEvent('change', payload);
|
|
1191
|
+
if (payload.cancel === true) {
|
|
1192
|
+
return;
|
|
1193
|
+
}
|
|
1194
|
+
this._headerChecked = checked;
|
|
1195
|
+
this._headerCheckElement.checked = checked;
|
|
1196
|
+
if (this._targetElements) {
|
|
1197
|
+
this._targetElements.forEach(function (element) {
|
|
1198
|
+
if (element) {
|
|
1199
|
+
element.checked = checked;
|
|
1200
|
+
}
|
|
1201
|
+
});
|
|
1202
|
+
}
|
|
1203
|
+
this._fireEvent('changed');
|
|
1204
|
+
this._dispatchEvent('changed');
|
|
1205
|
+
};
|
|
1206
|
+
/**
|
|
1207
|
+
* Toggle checkbox state
|
|
1208
|
+
* @param event The event if available
|
|
1209
|
+
* @returns {void}
|
|
1210
|
+
*/
|
|
1211
|
+
KTDataTable.prototype._checkboxToggle = function (event) {
|
|
1212
|
+
var checked = !this._isChecked();
|
|
1213
|
+
var eventType = checked ? 'checked' : 'unchecked';
|
|
1214
|
+
this._fireEvent(eventType);
|
|
1215
|
+
this._dispatchEvent(eventType);
|
|
1216
|
+
this._change(checked);
|
|
1217
|
+
};
|
|
1218
|
+
/**
|
|
1219
|
+
* Update checkbox state based on checked rows
|
|
1220
|
+
* @param event The event if available
|
|
1221
|
+
* @returns {void}
|
|
1222
|
+
*/
|
|
1223
|
+
KTDataTable.prototype._checkboxUpdate = function (event) {
|
|
1224
|
+
var checked = 0;
|
|
1225
|
+
var total = this._targetElements.length;
|
|
1226
|
+
for (var i = 0; i < total; i++) {
|
|
1227
|
+
var element = this._targetElements[i];
|
|
1228
|
+
if (!element) {
|
|
1229
|
+
continue;
|
|
1230
|
+
}
|
|
1231
|
+
var row = element.closest('tr');
|
|
1232
|
+
if (!row) {
|
|
1233
|
+
continue;
|
|
1234
|
+
}
|
|
1235
|
+
if (element.checked) {
|
|
1236
|
+
row.classList.add(this._config.checkbox.checkedClass);
|
|
1237
|
+
checked++;
|
|
1238
|
+
}
|
|
1239
|
+
else {
|
|
1240
|
+
row.classList.remove(this._config.checkbox.checkedClass);
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
if (checked === 0) {
|
|
1244
|
+
this._headerCheckElement.indeterminate = false;
|
|
1245
|
+
this._change(false);
|
|
1246
|
+
}
|
|
1247
|
+
if (checked > 0 && checked < total) {
|
|
1248
|
+
this._headerCheckElement.indeterminate = true;
|
|
1249
|
+
}
|
|
1250
|
+
if (checked === total) {
|
|
1251
|
+
this._headerCheckElement.indeterminate = false;
|
|
1252
|
+
this._change(true);
|
|
1253
|
+
}
|
|
1254
|
+
};
|
|
1255
|
+
/**
|
|
1256
|
+
* Get checked row IDs
|
|
1257
|
+
* @returns {string[]} An array of checked row IDs
|
|
1258
|
+
*/
|
|
1259
|
+
KTDataTable.prototype._getChecked = function () {
|
|
1260
|
+
var checked = [];
|
|
1261
|
+
this._targetElements.forEach(function (element) {
|
|
1262
|
+
if (element && element.checked) {
|
|
1263
|
+
var value = element.value;
|
|
1264
|
+
if (value) {
|
|
1265
|
+
checked.push(value);
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
});
|
|
1269
|
+
return checked;
|
|
1270
|
+
};
|
|
1271
|
+
KTDataTable.prototype.isChecked = function () {
|
|
1272
|
+
return this._isChecked();
|
|
1273
|
+
};
|
|
1274
|
+
KTDataTable.prototype.toggle = function () {
|
|
1275
|
+
this._checkboxToggle();
|
|
1276
|
+
};
|
|
1277
|
+
/**
|
|
1278
|
+
* Check all rows
|
|
1279
|
+
* @returns {void}
|
|
1280
|
+
*/
|
|
1281
|
+
KTDataTable.prototype.check = function () {
|
|
1282
|
+
this._change(true);
|
|
1283
|
+
this._checkboxUpdate();
|
|
1284
|
+
};
|
|
1285
|
+
/**
|
|
1286
|
+
* Uncheck all rows
|
|
1287
|
+
* @returns {void}
|
|
1288
|
+
*/
|
|
1289
|
+
KTDataTable.prototype.uncheck = function () {
|
|
1290
|
+
this._change(false);
|
|
1291
|
+
};
|
|
1292
|
+
/**
|
|
1293
|
+
* Get checked row IDs
|
|
1294
|
+
* @returns {string[]} An array of checked row IDs
|
|
1295
|
+
*/
|
|
1296
|
+
KTDataTable.prototype.getChecked = function () {
|
|
1297
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1298
|
+
return this._getChecked();
|
|
1299
|
+
};
|
|
1300
|
+
KTDataTable.prototype.update = function () {
|
|
1301
|
+
this._checkboxUpdate();
|
|
1302
|
+
};
|
|
1303
|
+
/**
|
|
1304
|
+
* Gets the current state of the table.
|
|
1305
|
+
* @returns {KTDataTableStateInterface} The current state of the table.
|
|
1306
|
+
*/
|
|
1307
|
+
KTDataTable.prototype.getState = function () {
|
|
1308
|
+
return __assign({
|
|
1309
|
+
/**
|
|
1310
|
+
* The current page number.
|
|
1311
|
+
*/
|
|
1312
|
+
page: 1,
|
|
1313
|
+
/**
|
|
1314
|
+
* The field that the data is sorted by.
|
|
1315
|
+
*/
|
|
1316
|
+
sortField: null,
|
|
1317
|
+
/**
|
|
1318
|
+
* The sort order (ascending or descending).
|
|
1319
|
+
*/
|
|
1320
|
+
sortOrder: '',
|
|
1321
|
+
/**
|
|
1322
|
+
* The number of rows to display per page.
|
|
1323
|
+
*/
|
|
1324
|
+
pageSize: this._config.pageSize, filters: [] }, this._config._state);
|
|
1325
|
+
};
|
|
1326
|
+
/**
|
|
1327
|
+
* Sorts the data in the table by the specified field.
|
|
1328
|
+
* @param field The field to sort by.
|
|
1329
|
+
*/
|
|
1330
|
+
KTDataTable.prototype.sort = function (field) {
|
|
1331
|
+
// Sort the data
|
|
1332
|
+
this._sort(field);
|
|
1333
|
+
};
|
|
1334
|
+
/**
|
|
1335
|
+
* Navigates to the specified page in the data table.
|
|
1336
|
+
* @param page The page number to navigate to.
|
|
1337
|
+
*/
|
|
1338
|
+
KTDataTable.prototype.goPage = function (page) {
|
|
1339
|
+
if (page < 1 || !Number.isInteger(page)) {
|
|
1340
|
+
return;
|
|
1341
|
+
}
|
|
1342
|
+
// Navigate to the specified page
|
|
1343
|
+
this._paginateData(page);
|
|
1344
|
+
};
|
|
1345
|
+
/**
|
|
1346
|
+
* Set the page size of the data table.
|
|
1347
|
+
* @param pageSize The new page size.
|
|
1348
|
+
*/
|
|
1349
|
+
KTDataTable.prototype.setPageSize = function (pageSize) {
|
|
1350
|
+
if (!Number.isInteger(pageSize)) {
|
|
1351
|
+
return;
|
|
1352
|
+
}
|
|
1353
|
+
/**
|
|
1354
|
+
* Reload the page size of the data table.
|
|
1355
|
+
* @param pageSize The new page size.
|
|
1356
|
+
*/
|
|
1357
|
+
this._reloadPageSize(pageSize);
|
|
1358
|
+
};
|
|
1359
|
+
/**
|
|
1360
|
+
* Reloads the data from the server and updates the table.
|
|
1361
|
+
* Triggers the 'reload' event and the 'kt.datatable.reload' custom event.
|
|
1362
|
+
*/
|
|
1363
|
+
KTDataTable.prototype.reload = function () {
|
|
1364
|
+
this._fireEvent('reload');
|
|
1365
|
+
this._dispatchEvent('reload');
|
|
1366
|
+
// Fetch the data from the server using the current sort and filter settings
|
|
1367
|
+
this._updateData();
|
|
1368
|
+
};
|
|
1369
|
+
KTDataTable.prototype.redraw = function (page) {
|
|
1370
|
+
if (page === void 0) { page = 1; }
|
|
1371
|
+
this._fireEvent('redraw');
|
|
1372
|
+
this._dispatchEvent('redraw');
|
|
1373
|
+
this._paginateData(page);
|
|
1374
|
+
};
|
|
1375
|
+
/**
|
|
1376
|
+
* Show the loading spinner of the data table.
|
|
1377
|
+
*/
|
|
1378
|
+
KTDataTable.prototype.showSpinner = function () {
|
|
1379
|
+
/**
|
|
1380
|
+
* Show the loading spinner of the data table.
|
|
1381
|
+
*/
|
|
1382
|
+
this._showSpinner();
|
|
1383
|
+
};
|
|
1384
|
+
/**
|
|
1385
|
+
* Hide the loading spinner of the data table.
|
|
1386
|
+
*/
|
|
1387
|
+
KTDataTable.prototype.hideSpinner = function () {
|
|
1388
|
+
/**
|
|
1389
|
+
* Hide the loading spinner of the data table.
|
|
1390
|
+
*/
|
|
1391
|
+
this._hideSpinner();
|
|
1392
|
+
};
|
|
1393
|
+
/**
|
|
1394
|
+
* Filter data using the specified filter object.
|
|
1395
|
+
* Replaces the existing filter object for the column with the new one.
|
|
1396
|
+
* @param filter Filter object containing the column name and its value.
|
|
1397
|
+
* @returns The KTDataTable instance.
|
|
1398
|
+
* @throws Error if the filter object is null or undefined.
|
|
1399
|
+
*/
|
|
1400
|
+
KTDataTable.prototype.setFilter = function (filter) {
|
|
1401
|
+
this._config._state.filters = __spreadArray(__spreadArray([], (this.getState().filters || []).filter(function (f) { return f.column !== filter.column; }), true), [
|
|
1402
|
+
filter
|
|
1403
|
+
], false);
|
|
1404
|
+
return this;
|
|
1405
|
+
};
|
|
1406
|
+
KTDataTable.prototype.dispose = function () {
|
|
1407
|
+
this._dispose();
|
|
1408
|
+
};
|
|
1409
|
+
KTDataTable.prototype.search = function (query) {
|
|
1410
|
+
this._config._state.search = query;
|
|
1411
|
+
this.reload();
|
|
1412
|
+
};
|
|
1413
|
+
/**
|
|
1414
|
+
* Create KTDataTable instances for all elements with a data-datatable="true" attribute.
|
|
1415
|
+
*
|
|
1416
|
+
* This function should be called after the control(s) have been
|
|
1417
|
+
* loaded and parsed by the browser. It will create instances of
|
|
1418
|
+
* KTDataTable for all elements with a data-datatable="true" attribute.
|
|
1419
|
+
*/
|
|
1420
|
+
KTDataTable.createInstances = function () {
|
|
1421
|
+
var _this = this;
|
|
1422
|
+
var elements = document.querySelectorAll('[data-datatable="true"]');
|
|
1423
|
+
elements.forEach(function (element) {
|
|
1424
|
+
if (element.hasAttribute('data-datatable') && !element.classList.contains('datatable-initialized')) {
|
|
1425
|
+
/**
|
|
1426
|
+
* Create an instance of KTDataTable for the given element
|
|
1427
|
+
* @param element The element to create an instance for
|
|
1428
|
+
*/
|
|
1429
|
+
var instance = new KTDataTable(element);
|
|
1430
|
+
_this._instances.set(element, instance);
|
|
1431
|
+
}
|
|
1432
|
+
});
|
|
1433
|
+
};
|
|
1434
|
+
/**
|
|
1435
|
+
* Get the KTDataTable instance for a given element.
|
|
1436
|
+
*
|
|
1437
|
+
* @param element The element to retrieve the instance for
|
|
1438
|
+
* @returns The KTDataTable instance or undefined if not found
|
|
1439
|
+
*/
|
|
1440
|
+
KTDataTable.getInstance = function (element) {
|
|
1441
|
+
return this._instances.get(element);
|
|
1442
|
+
};
|
|
1443
|
+
/**
|
|
1444
|
+
* Initializes all KTDataTable instances on the page.
|
|
1445
|
+
*
|
|
1446
|
+
* This function should be called after the control(s) have been
|
|
1447
|
+
* loaded and parsed by the browser.
|
|
1448
|
+
*/
|
|
1449
|
+
KTDataTable.init = function () {
|
|
1450
|
+
// Create instances of KTDataTable for all elements with a
|
|
1451
|
+
// data-datatable="true" attribute
|
|
1452
|
+
KTDataTable.createInstances();
|
|
1453
|
+
};
|
|
1454
|
+
/**
|
|
1455
|
+
* Static variables
|
|
1456
|
+
*/
|
|
1457
|
+
KTDataTable._instances = new Map();
|
|
1458
|
+
return KTDataTable;
|
|
1459
|
+
}(KTComponent));
|
|
1460
|
+
export { KTDataTable };
|
|
1461
|
+
//# sourceMappingURL=datatable.js.map
|