@nuralyui/table 0.0.3 → 0.0.6
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/bundle.js +1497 -0
- package/package.json +16 -2
- package/react.js +1 -1
- package/react.js.map +1 -1
- package/table.component.d.ts +85 -12
- package/table.component.js +229 -136
- package/table.component.js.map +1 -1
- package/table.style.js +253 -2
- package/table.style.js.map +1 -1
- package/table.types.d.ts +22 -4
- package/table.types.js +0 -23
- package/table.types.js.map +1 -1
- package/components/hy-table-actions.d.ts +0 -10
- package/components/hy-table-actions.d.ts.map +0 -1
- package/components/hy-table-actions.js +0 -39
- package/components/hy-table-actions.js.map +0 -1
- package/components/hy-table-content.d.ts +0 -25
- package/components/hy-table-content.d.ts.map +0 -1
- package/components/hy-table-content.js +0 -168
- package/components/hy-table-content.js.map +0 -1
- package/components/hy-table-filter.d.ts +0 -11
- package/components/hy-table-filter.d.ts.map +0 -1
- package/components/hy-table-filter.js +0 -59
- package/components/hy-table-filter.js.map +0 -1
- package/components/hy-table-pagination.d.ts +0 -21
- package/components/hy-table-pagination.d.ts.map +0 -1
- package/components/hy-table-pagination.js +0 -111
- package/components/hy-table-pagination.js.map +0 -1
- package/components/table-actions.style.d.ts +0 -2
- package/components/table-actions.style.d.ts.map +0 -1
- package/components/table-actions.style.js +0 -31
- package/components/table-actions.style.js.map +0 -1
- package/components/table-actions.variables.d.ts +0 -2
- package/components/table-actions.variables.d.ts.map +0 -1
- package/components/table-actions.variables.js +0 -13
- package/components/table-actions.variables.js.map +0 -1
- package/components/table-content.style.d.ts +0 -2
- package/components/table-content.style.d.ts.map +0 -1
- package/components/table-content.style.js +0 -77
- package/components/table-content.style.js.map +0 -1
- package/components/table-content.variables.d.ts +0 -2
- package/components/table-content.variables.d.ts.map +0 -1
- package/components/table-content.variables.js +0 -29
- package/components/table-content.variables.js.map +0 -1
- package/components/table-filter.style.d.ts +0 -2
- package/components/table-filter.style.d.ts.map +0 -1
- package/components/table-filter.style.js +0 -39
- package/components/table-filter.style.js.map +0 -1
- package/components/table-filter.variables.d.ts +0 -2
- package/components/table-filter.variables.d.ts.map +0 -1
- package/components/table-filter.variables.js +0 -17
- package/components/table-filter.variables.js.map +0 -1
- package/components/table-pagination.style.d.ts +0 -2
- package/components/table-pagination.style.d.ts.map +0 -1
- package/components/table-pagination.style.js +0 -102
- package/components/table-pagination.style.js.map +0 -1
- package/components/table-pagination.variables.d.ts +0 -2
- package/components/table-pagination.variables.d.ts.map +0 -1
- package/components/table-pagination.variables.js +0 -17
- package/components/table-pagination.variables.js.map +0 -1
- package/demo/table-demo.d.ts +0 -17
- package/demo/table-demo.d.ts.map +0 -1
- package/demo/table-demo.js +0 -166
- package/demo/table-demo.js.map +0 -1
- package/index.d.ts.map +0 -1
- package/react.d.ts.map +0 -1
- package/table.component.d.ts.map +0 -1
- package/table.style.d.ts.map +0 -1
- package/table.types.d.ts.map +0 -1
- package/test/hy-table-actions_test.d.ts +0 -2
- package/test/hy-table-actions_test.d.ts.map +0 -1
- package/test/hy-table-actions_test.js +0 -32
- package/test/hy-table-actions_test.js.map +0 -1
- package/test/hy-table-content_test.d.ts +0 -2
- package/test/hy-table-content_test.d.ts.map +0 -1
- package/test/hy-table-content_test.js +0 -168
- package/test/hy-table-content_test.js.map +0 -1
- package/test/hy-table-filter_test.d.ts +0 -2
- package/test/hy-table-filter_test.d.ts.map +0 -1
- package/test/hy-table-filter_test.js +0 -80
- package/test/hy-table-filter_test.js.map +0 -1
- package/test/hy-table-pagination_test.d.ts +0 -2
- package/test/hy-table-pagination_test.d.ts.map +0 -1
- package/test/hy-table-pagination_test.js +0 -114
- package/test/hy-table-pagination_test.js.map +0 -1
- package/test/hy-table_test.d.ts +0 -2
- package/test/hy-table_test.d.ts.map +0 -1
- package/test/hy-table_test.js +0 -145
- package/test/hy-table_test.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuralyui/table",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -11,5 +11,19 @@
|
|
|
11
11
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
12
12
|
},
|
|
13
13
|
"author": "Labidi Aymen",
|
|
14
|
-
"license": "ISC"
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"import": "./index.js"
|
|
18
|
+
},
|
|
19
|
+
"./bundle": {
|
|
20
|
+
"import": "./bundle.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"bundle.js",
|
|
25
|
+
"*.js",
|
|
26
|
+
"*.d.ts",
|
|
27
|
+
"*.js.map"
|
|
28
|
+
]
|
|
15
29
|
}
|
package/react.js
CHANGED
|
@@ -2,7 +2,7 @@ import { createComponent } from '@lit-labs/react';
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { HyTable } from './table.component.js';
|
|
4
4
|
export const HyTableComponent = createComponent({
|
|
5
|
-
tagName: '
|
|
5
|
+
tagName: 'nr-table',
|
|
6
6
|
elementClass: HyTable,
|
|
7
7
|
react: React,
|
|
8
8
|
events: {
|
package/react.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.js","sourceRoot":"","sources":["../../../src/components/table/react.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,MAAM,CAAC,MAAM,gBAAgB,GAAG,eAAe,CAAC;IAC9C,OAAO,EAAE,UAAU;IACnB,YAAY,EAAE,OAAO;IACrB,KAAK,EAAE,KAAK;IACZ,MAAM,EAAE;QACN,QAAQ,EAAE,WAAW;QACrB,UAAU,EAAE,aAAa;QACzB,eAAe,EAAE,kBAAkB;KACpC;CACF,CAAC,CAAC","sourcesContent":["import { createComponent } from '@lit-labs/react';\nimport * as React from 'react';\nimport { HyTable } from './table.component.js';\n\nexport const HyTableComponent = createComponent({\n tagName: '
|
|
1
|
+
{"version":3,"file":"react.js","sourceRoot":"","sources":["../../../src/components/table/react.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,MAAM,CAAC,MAAM,gBAAgB,GAAG,eAAe,CAAC;IAC9C,OAAO,EAAE,UAAU;IACnB,YAAY,EAAE,OAAO;IACrB,KAAK,EAAE,KAAK;IACZ,MAAM,EAAE;QACN,QAAQ,EAAE,WAAW;QACrB,UAAU,EAAE,aAAa;QACzB,eAAe,EAAE,kBAAkB;KACpC;CACF,CAAC,CAAC","sourcesContent":["import { createComponent } from '@lit-labs/react';\nimport * as React from 'react';\nimport { HyTable } from './table.component.js';\n\nexport const HyTableComponent = createComponent({\n tagName: 'nr-table',\n elementClass: HyTable,\n react: React,\n events: {\n rowClick: 'row-click',\n sortChange: 'sort-change',\n selectionChange: 'selection-change',\n },\n});\n"]}
|
package/table.component.d.ts
CHANGED
|
@@ -1,39 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2023 Nuraly, Laabidi Aymen
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
1
6
|
import { LitElement, PropertyValueMap } from 'lit';
|
|
2
|
-
import './components/hy-table-actions.js';
|
|
3
|
-
import './components/hy-table-filter.js';
|
|
4
|
-
import './components/hy-table-pagination.js';
|
|
5
|
-
import './components/hy-table-content.js';
|
|
6
7
|
import { IHeader, SelectionMode, Sizes, SortAttribute } from './table.types.js';
|
|
7
|
-
|
|
8
|
+
import '../select/select.component.js';
|
|
9
|
+
import '../icon/icon.component.js';
|
|
10
|
+
import { TableHost } from './interfaces/index.js';
|
|
11
|
+
declare const HyTable_base: (new (...args: any[]) => import("../../shared/dependency-mixin.js").DependencyAware) & (new (...args: any[]) => import("../../shared/theme-mixin.js").ThemeAware) & (new (...args: any[]) => import("../../shared/event-handler-mixin.js").EventHandlerCapable) & typeof LitElement;
|
|
12
|
+
/**
|
|
13
|
+
* Advanced table component with sorting, filtering, pagination, and selection capabilities.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```html
|
|
17
|
+
* <nr-table
|
|
18
|
+
* .headers=${headers}
|
|
19
|
+
* .rows=${data}
|
|
20
|
+
* size="normal"
|
|
21
|
+
* selectionMode="multiple">
|
|
22
|
+
* </nr-table>
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @fires onPaginate - Fired when pagination changes
|
|
26
|
+
* @fires onSelect - Fired when row selection changes
|
|
27
|
+
* @fires onSearch - Fired when search/filter is applied
|
|
28
|
+
* @fires onSort - Fired when sorting is applied
|
|
29
|
+
*/
|
|
30
|
+
export declare class HyTable extends HyTable_base implements TableHost {
|
|
8
31
|
static styles: import("lit").CSSResult;
|
|
9
32
|
headers: IHeader[];
|
|
10
|
-
rows: [];
|
|
33
|
+
rows: any[];
|
|
11
34
|
size: Sizes;
|
|
12
35
|
withFilter: boolean;
|
|
13
36
|
expandable: string | undefined;
|
|
14
37
|
selectionMode: SelectionMode | undefined;
|
|
15
38
|
itemPerPage: number[];
|
|
16
39
|
selectedItemPerPage: number;
|
|
17
|
-
displayedRows:
|
|
40
|
+
displayedRows: any[];
|
|
18
41
|
selectedItems: boolean[];
|
|
19
42
|
currentPage: number;
|
|
20
|
-
rowsCopy: [];
|
|
43
|
+
rowsCopy: any[];
|
|
21
44
|
activeSearch: boolean;
|
|
22
45
|
sortAttribute: SortAttribute;
|
|
46
|
+
expand: boolean[];
|
|
47
|
+
showFilterInput: boolean;
|
|
48
|
+
filterValue: string;
|
|
49
|
+
globalCheck?: HTMLElement;
|
|
50
|
+
requiredComponents: string[];
|
|
51
|
+
private selectionController;
|
|
52
|
+
private paginationController;
|
|
53
|
+
private sortController;
|
|
54
|
+
private filterController;
|
|
23
55
|
connectedCallback(): void;
|
|
56
|
+
updated(_changedProperties: PropertyValueMap<this> | Map<PropertyKey, unknown>): void;
|
|
24
57
|
willUpdate(_changedProperties: PropertyValueMap<this>): void;
|
|
25
|
-
|
|
26
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Initialize or reset pagination state
|
|
60
|
+
*/
|
|
61
|
+
private _initPagination;
|
|
62
|
+
/**
|
|
63
|
+
* Handle items per page change event
|
|
64
|
+
*/
|
|
27
65
|
_handleItemPerPage(itemPerPageEvent: CustomEvent): void;
|
|
66
|
+
/**
|
|
67
|
+
* Handle page navigation event
|
|
68
|
+
*/
|
|
28
69
|
_handleUpdatePage(updatePageEvent: CustomEvent): void;
|
|
70
|
+
/**
|
|
71
|
+
* Handle check all rows event
|
|
72
|
+
*/
|
|
29
73
|
_handleCheckAll(checkAllEvent: CustomEvent): void;
|
|
74
|
+
/**
|
|
75
|
+
* Handle check single row event
|
|
76
|
+
*/
|
|
30
77
|
_handleCheckOne(checkOneEvent: CustomEvent): void;
|
|
78
|
+
/**
|
|
79
|
+
* Handle select single row event (radio button mode)
|
|
80
|
+
*/
|
|
31
81
|
_handleSelectOne(selectOneEvent: CustomEvent): void;
|
|
82
|
+
/**
|
|
83
|
+
* Handle cancel selection action
|
|
84
|
+
*/
|
|
32
85
|
_handleCancelSelection(): void;
|
|
86
|
+
/**
|
|
87
|
+
* Handle search/filter input
|
|
88
|
+
*/
|
|
33
89
|
_handleSearch(searchEvent: CustomEvent): void;
|
|
90
|
+
/**
|
|
91
|
+
* Handle column sort order change
|
|
92
|
+
*/
|
|
34
93
|
_handleSortOrder(sortOrderEvent: CustomEvent): void;
|
|
35
|
-
|
|
36
|
-
|
|
94
|
+
/**
|
|
95
|
+
* Toggle expanded content for a row
|
|
96
|
+
*/
|
|
97
|
+
private _showExpandedContent;
|
|
98
|
+
/**
|
|
99
|
+
* Toggle filter input visibility
|
|
100
|
+
*/
|
|
101
|
+
private _toggleFilterInput;
|
|
102
|
+
/**
|
|
103
|
+
* Handle filter input change
|
|
104
|
+
*/
|
|
105
|
+
private _handleFilterInputChange;
|
|
106
|
+
/**
|
|
107
|
+
* Render the table component with all templates
|
|
108
|
+
*/
|
|
37
109
|
render(): import("lit").TemplateResult<1>;
|
|
38
110
|
}
|
|
111
|
+
export {};
|
|
39
112
|
//# sourceMappingURL=table.component.d.ts.map
|
package/table.component.js
CHANGED
|
@@ -1,22 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2023 Nuraly, Laabidi Aymen
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
1
6
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
7
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
8
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
9
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
10
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
11
|
};
|
|
7
|
-
import styles from './table.style.js';
|
|
8
12
|
import { LitElement, html, nothing } from 'lit';
|
|
9
|
-
import { customElement, property, state } from 'lit/decorators.js';
|
|
10
|
-
import '
|
|
11
|
-
import './
|
|
12
|
-
import './
|
|
13
|
-
|
|
14
|
-
import
|
|
15
|
-
|
|
13
|
+
import { customElement, property, state, query } from 'lit/decorators.js';
|
|
14
|
+
import { NuralyUIBaseMixin } from '../../shared/base-mixin.js';
|
|
15
|
+
import styles from './table.style.js';
|
|
16
|
+
import { EMPTY_STRING } from './table.types.js';
|
|
17
|
+
// Import required components
|
|
18
|
+
import '../select/select.component.js';
|
|
19
|
+
import '../icon/icon.component.js';
|
|
20
|
+
// Import controllers
|
|
21
|
+
import { TableSelectionController, TablePaginationController, TableSortController, TableFilterController } from './controllers/index.js';
|
|
22
|
+
// Import templates
|
|
23
|
+
import { renderPaginationTemplate, renderContentTemplate, renderActionsTemplate, renderFilterTemplate } from './templates/index.js';
|
|
24
|
+
/**
|
|
25
|
+
* Advanced table component with sorting, filtering, pagination, and selection capabilities.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```html
|
|
29
|
+
* <nr-table
|
|
30
|
+
* .headers=${headers}
|
|
31
|
+
* .rows=${data}
|
|
32
|
+
* size="normal"
|
|
33
|
+
* selectionMode="multiple">
|
|
34
|
+
* </nr-table>
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @fires onPaginate - Fired when pagination changes
|
|
38
|
+
* @fires onSelect - Fired when row selection changes
|
|
39
|
+
* @fires onSearch - Fired when search/filter is applied
|
|
40
|
+
* @fires onSort - Fired when sorting is applied
|
|
41
|
+
*/
|
|
42
|
+
let HyTable = class HyTable extends NuralyUIBaseMixin(LitElement) {
|
|
16
43
|
constructor() {
|
|
17
44
|
super(...arguments);
|
|
18
45
|
this.rows = [];
|
|
19
|
-
this.size = Sizes.Normal
|
|
46
|
+
this.size = "normal" /* Sizes.Normal */;
|
|
20
47
|
this.withFilter = false;
|
|
21
48
|
this.itemPerPage = [5, 10, 15, 20];
|
|
22
49
|
this.selectedItemPerPage = this.itemPerPage[0];
|
|
@@ -24,175 +51,229 @@ let HyTable = class HyTable extends LitElement {
|
|
|
24
51
|
this.selectedItems = [];
|
|
25
52
|
this.rowsCopy = [];
|
|
26
53
|
this.activeSearch = false;
|
|
27
|
-
this.sortAttribute = { index: -1, order: SortOrder.Default };
|
|
54
|
+
this.sortAttribute = { index: -1, order: "default" /* SortOrder.Default */ };
|
|
55
|
+
this.expand = [];
|
|
56
|
+
this.showFilterInput = false;
|
|
57
|
+
this.filterValue = EMPTY_STRING;
|
|
58
|
+
this.requiredComponents = ['hy-select', 'nr-icon', 'nr-checkbox'];
|
|
59
|
+
// Controllers
|
|
60
|
+
this.selectionController = new TableSelectionController(this);
|
|
61
|
+
this.paginationController = new TablePaginationController(this);
|
|
62
|
+
this.sortController = new TableSortController(this);
|
|
63
|
+
this.filterController = new TableFilterController(this);
|
|
28
64
|
}
|
|
29
65
|
connectedCallback() {
|
|
30
66
|
super.connectedCallback();
|
|
31
|
-
this.
|
|
67
|
+
this.selectionController.initSelection();
|
|
68
|
+
}
|
|
69
|
+
updated(_changedProperties) {
|
|
70
|
+
var _a, _b;
|
|
71
|
+
if (this.globalCheck && (_changedProperties.has('selectedItems') || _changedProperties.has('currentPage') || _changedProperties.has('displayedRows'))) {
|
|
72
|
+
const checkbox = this.globalCheck;
|
|
73
|
+
// Get the selection state for the current page only
|
|
74
|
+
const startIndex = (this.currentPage - 1) * this.selectedItemPerPage;
|
|
75
|
+
const endIndex = Math.min(startIndex + this.displayedRows.length, this.selectedItems.length);
|
|
76
|
+
const currentPageSelections = this.selectedItems.slice(startIndex, endIndex);
|
|
77
|
+
if (currentPageSelections.length > 0 && currentPageSelections.every((isSelected) => isSelected)) {
|
|
78
|
+
checkbox.checked = true;
|
|
79
|
+
checkbox.indeterminate = false;
|
|
80
|
+
}
|
|
81
|
+
else if (currentPageSelections.some((isSelected) => isSelected)) {
|
|
82
|
+
checkbox.checked = false;
|
|
83
|
+
checkbox.indeterminate = true;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
checkbox.checked = false;
|
|
87
|
+
checkbox.indeterminate = false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (this.showFilterInput && _changedProperties.has('showFilterInput')) {
|
|
91
|
+
(_b = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('input')) === null || _b === void 0 ? void 0 : _b.focus();
|
|
92
|
+
}
|
|
32
93
|
}
|
|
33
94
|
willUpdate(_changedProperties) {
|
|
34
|
-
if (_changedProperties.has('
|
|
95
|
+
if (_changedProperties.has('rows')) {
|
|
96
|
+
this.expand = Array(this.rows.length).fill(false);
|
|
97
|
+
}
|
|
98
|
+
if (_changedProperties.has('sortAttribute') && this.sortController.isSortActive()) {
|
|
35
99
|
this._initPagination();
|
|
36
|
-
this.
|
|
100
|
+
this.selectionController.initSelection();
|
|
37
101
|
}
|
|
38
102
|
if (_changedProperties.has('rowsCopy')) {
|
|
39
|
-
if (this.
|
|
103
|
+
if (this.filterController.isSearchActive()) {
|
|
40
104
|
this._initPagination();
|
|
41
105
|
}
|
|
42
106
|
}
|
|
43
107
|
if (_changedProperties.has('activeSearch') || _changedProperties.has('rows')) {
|
|
44
|
-
if (!this.
|
|
108
|
+
if (!this.filterController.isSearchActive()) {
|
|
45
109
|
this.rowsCopy = [...this.rows];
|
|
46
110
|
this._initPagination();
|
|
47
111
|
}
|
|
48
112
|
}
|
|
49
113
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
114
|
+
/**
|
|
115
|
+
* Initialize or reset pagination state
|
|
116
|
+
*/
|
|
54
117
|
_initPagination() {
|
|
55
|
-
if (this.
|
|
56
|
-
if (this.
|
|
57
|
-
this.
|
|
58
|
-
|
|
59
|
-
|
|
118
|
+
if (this.sortController.isSortActive()) {
|
|
119
|
+
if (!this.sortController.isSortDefault()) {
|
|
120
|
+
this.sortController.sort();
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
this.sortController.resetSort();
|
|
124
|
+
}
|
|
60
125
|
}
|
|
61
|
-
this.
|
|
62
|
-
this.currentPage = this.rowsCopy.length > 0 ? 1 : 0;
|
|
126
|
+
this.paginationController.initPagination();
|
|
63
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Handle items per page change event
|
|
130
|
+
*/
|
|
64
131
|
_handleItemPerPage(itemPerPageEvent) {
|
|
65
|
-
|
|
66
|
-
this.
|
|
132
|
+
const value = itemPerPageEvent.detail.value || itemPerPageEvent.detail.selectedItemPerPage;
|
|
133
|
+
this.paginationController.handleItemPerPageChange(Number(value));
|
|
67
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Handle page navigation event
|
|
137
|
+
*/
|
|
68
138
|
_handleUpdatePage(updatePageEvent) {
|
|
69
|
-
this.
|
|
70
|
-
this.displayedRows = this.rowsCopy.slice((updatePageEvent.detail.page - 1) * this.selectedItemPerPage, (updatePageEvent.detail.page - 1) * this.selectedItemPerPage + this.selectedItemPerPage);
|
|
71
|
-
this.dispatchEvent(new CustomEvent('onPaginate', { bubbles: true, composed: true, detail: { value: this.currentPage } }));
|
|
139
|
+
this.paginationController.handlePageChange(updatePageEvent.detail.page);
|
|
72
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Handle check all rows event
|
|
143
|
+
*/
|
|
73
144
|
_handleCheckAll(checkAllEvent) {
|
|
74
|
-
|
|
75
|
-
this.selectedItems = everyItemChecked ? this.selectedItems.map(() => false) : this.selectedItems.map(() => true);
|
|
76
|
-
this.dispatchEvent(new CustomEvent('onSelect', { bubbles: true, composed: true, detail: { value: this.rowsCopy.filter((_, i) => this.selectedItems[i]) } }));
|
|
145
|
+
this.selectionController.handleCheckAll(checkAllEvent.detail.isEveryItemChecked);
|
|
77
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* Handle check single row event
|
|
149
|
+
*/
|
|
78
150
|
_handleCheckOne(checkOneEvent) {
|
|
79
|
-
|
|
80
|
-
this.selectedItems[indexSelected + (this.currentPage - 1) * this.selectedItemPerPage] = checkOneEvent.detail.value;
|
|
81
|
-
this.selectedItems = [...this.selectedItems];
|
|
82
|
-
this.dispatchEvent(new CustomEvent('onSelect', { bubbles: true, composed: true, detail: { value: this.rowsCopy.filter((_, i) => this.selectedItems[i]) } }));
|
|
151
|
+
this.selectionController.handleCheckOne(checkOneEvent.detail.index, checkOneEvent.detail.value);
|
|
83
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Handle select single row event (radio button mode)
|
|
155
|
+
*/
|
|
84
156
|
_handleSelectOne(selectOneEvent) {
|
|
85
|
-
|
|
86
|
-
if (previousSelected > -1) {
|
|
87
|
-
this.selectedItems[previousSelected] = false;
|
|
88
|
-
}
|
|
89
|
-
const indexSelected = selectOneEvent.detail.index;
|
|
90
|
-
this.selectedItems[indexSelected + (this.currentPage - 1) * this.selectedItemPerPage] = true;
|
|
91
|
-
this.selectedItems = [...this.selectedItems];
|
|
92
|
-
this.dispatchEvent(new CustomEvent('onSelect', { bubbles: true, composed: true, detail: { value: this.rowsCopy.filter((_, i) => this.selectedItems[i]) } }));
|
|
157
|
+
this.selectionController.handleSelectOne(selectOneEvent.detail.index);
|
|
93
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Handle cancel selection action
|
|
161
|
+
*/
|
|
94
162
|
_handleCancelSelection() {
|
|
95
|
-
this.
|
|
96
|
-
this.dispatchEvent(new CustomEvent('onSelect', { bubbles: true, composed: true, detail: { value: this.selectedItems } }));
|
|
163
|
+
this.selectionController.cancelSelection();
|
|
97
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Handle search/filter input
|
|
167
|
+
*/
|
|
98
168
|
_handleSearch(searchEvent) {
|
|
99
|
-
|
|
100
|
-
if (searchValue.trim().length > 0) {
|
|
101
|
-
this.activeSearch = true;
|
|
102
|
-
this.rowsCopy = this.rows.filter((rowValue) => {
|
|
103
|
-
return Object.values(rowValue).some((attributeValue) => {
|
|
104
|
-
const stringValue = JSON.stringify(attributeValue);
|
|
105
|
-
return stringValue.includes(searchValue);
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
this.dispatchEvent(new CustomEvent('onSearch', { bubbles: true, composed: true, detail: { value: this.rowsCopy } }));
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
this.activeSearch = false;
|
|
112
|
-
}
|
|
169
|
+
this.filterController.handleSearch(searchEvent.detail.value);
|
|
113
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Handle column sort order change
|
|
173
|
+
*/
|
|
114
174
|
_handleSortOrder(sortOrderEvent) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
this.
|
|
129
|
-
}
|
|
130
|
-
_sort() {
|
|
131
|
-
if (this.rowsCopy.length) {
|
|
132
|
-
const sortOrder = this.sortAttribute.order == SortOrder.Default
|
|
133
|
-
? SortValue.Default
|
|
134
|
-
: this.sortAttribute.order == SortOrder.Ascending
|
|
135
|
-
? SortValue.Ascending
|
|
136
|
-
: SortValue.Descending;
|
|
137
|
-
this.rowsCopy.sort((a, b) => {
|
|
138
|
-
const stringifyA = JSON.stringify(a[this.headers[this.sortAttribute.index].key]);
|
|
139
|
-
const stringifyB = JSON.stringify(b[this.headers[this.sortAttribute.index].key]);
|
|
140
|
-
const result = stringifyA < stringifyB ? -1 : stringifyA > stringifyB ? 1 : 0;
|
|
141
|
-
return result * sortOrder;
|
|
142
|
-
});
|
|
143
|
-
this.dispatchEvent(new CustomEvent('onSort', { bubbles: true, composed: true, detail: { value: this.rowsCopy } }));
|
|
144
|
-
}
|
|
175
|
+
this.sortController.handleSortOrderChange(sortOrderEvent.detail.index);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Toggle expanded content for a row
|
|
179
|
+
*/
|
|
180
|
+
_showExpandedContent(index) {
|
|
181
|
+
this.expand[index] = !this.expand[index];
|
|
182
|
+
this.requestUpdate();
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Toggle filter input visibility
|
|
186
|
+
*/
|
|
187
|
+
_toggleFilterInput() {
|
|
188
|
+
this.showFilterInput = !this.showFilterInput;
|
|
145
189
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
: positionInOriginalArrayA < positionInOriginalArrayB
|
|
153
|
-
? SortValue.Descending
|
|
154
|
-
: SortValue.Default;
|
|
155
|
-
});
|
|
190
|
+
/**
|
|
191
|
+
* Handle filter input change
|
|
192
|
+
*/
|
|
193
|
+
_handleFilterInputChange(event) {
|
|
194
|
+
this.filterValue = event.target.value;
|
|
195
|
+
this.filterController.handleSearch(this.filterValue);
|
|
156
196
|
}
|
|
197
|
+
/**
|
|
198
|
+
* Render the table component with all templates
|
|
199
|
+
*/
|
|
157
200
|
render() {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
.
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
201
|
+
const numberOfPages = Math.ceil(this.rowsCopy.length / this.selectedItemPerPage);
|
|
202
|
+
const fromItem = this.currentPage > 0
|
|
203
|
+
? this.currentPage * this.selectedItemPerPage - this.selectedItemPerPage + 1
|
|
204
|
+
: 0;
|
|
205
|
+
const toItem = this.currentPage * this.selectedItemPerPage <= this.rowsCopy.length
|
|
206
|
+
? this.currentPage * this.selectedItemPerPage
|
|
207
|
+
: this.rowsCopy.length;
|
|
208
|
+
const enableNext = toItem < this.rowsCopy.length;
|
|
209
|
+
const enablePrevious = fromItem > 1;
|
|
210
|
+
return html `
|
|
211
|
+
${this.selectionMode && !this.withFilter && this.selectionController.hasSelection()
|
|
212
|
+
? renderActionsTemplate({
|
|
213
|
+
selectedItems: this.selectionController.getSelectedCount(),
|
|
214
|
+
size: this.size,
|
|
215
|
+
onCancelSelection: () => this._handleCancelSelection()
|
|
216
|
+
})
|
|
164
217
|
: this.withFilter
|
|
165
218
|
? html `
|
|
166
219
|
<div class="filter-container">
|
|
167
|
-
|
|
220
|
+
${renderFilterTemplate({
|
|
221
|
+
showInput: this.showFilterInput,
|
|
222
|
+
value: this.filterValue,
|
|
223
|
+
onToggleInput: () => this._toggleFilterInput(),
|
|
224
|
+
onChange: (e) => this._handleFilterInputChange(e)
|
|
225
|
+
})}
|
|
168
226
|
</div>
|
|
169
227
|
`
|
|
170
228
|
: nothing}
|
|
171
|
-
<hy-table-content
|
|
172
|
-
.headers=${this.headers}
|
|
173
|
-
.rows=${this.displayedRows}
|
|
174
|
-
.expandable=${this.expandable && !this.selectionMode ? this.expandable : nothing}
|
|
175
|
-
.selectionMode=${this.selectionMode && !this.withFilter ? this.selectionMode : nothing}
|
|
176
|
-
.selectedItems=${this.selectedItems}
|
|
177
|
-
.currentPage=${this.currentPage}
|
|
178
|
-
.itemPerPage=${this.selectedItemPerPage}
|
|
179
|
-
.sortAttribute=${this.sortAttribute}
|
|
180
|
-
.size=${this.size}
|
|
181
|
-
@check-all=${this._handleCheckAll}
|
|
182
|
-
@check-one=${this._handleCheckOne}
|
|
183
|
-
@select-one=${this._handleSelectOne}
|
|
184
|
-
@update-sort=${this._handleSortOrder}
|
|
185
|
-
></hy-table-content>
|
|
186
229
|
|
|
187
|
-
<
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
230
|
+
<div class="table-content-wrapper">
|
|
231
|
+
${renderContentTemplate({
|
|
232
|
+
headers: this.headers,
|
|
233
|
+
rows: this.displayedRows,
|
|
234
|
+
expandable: this.expandable && !this.selectionMode ? this.expandable : undefined,
|
|
235
|
+
selectionMode: this.selectionMode && !this.withFilter ? this.selectionMode : undefined,
|
|
236
|
+
selectedItems: this.selectedItems,
|
|
237
|
+
currentPage: this.currentPage,
|
|
238
|
+
itemPerPage: this.selectedItemPerPage,
|
|
239
|
+
sortAttribute: this.sortAttribute,
|
|
240
|
+
expand: this.expand,
|
|
241
|
+
onCheckAll: () => {
|
|
242
|
+
const startIndex = (this.currentPage - 1) * this.selectedItemPerPage;
|
|
243
|
+
const endIndex = Math.min(startIndex + this.selectedItemPerPage, this.selectedItems.length);
|
|
244
|
+
const currentPageItems = this.selectedItems.slice(startIndex, endIndex);
|
|
245
|
+
const isEveryItemChecked = currentPageItems.every(i => i) && currentPageItems.length > 0;
|
|
246
|
+
this._handleCheckAll({ detail: { isEveryItemChecked } });
|
|
247
|
+
},
|
|
248
|
+
onCheckOne: (e, index) => this._handleCheckOne({ detail: { index, value: e.detail.checked } }),
|
|
249
|
+
onSelectOne: (index) => this._handleSelectOne({ detail: { index } }),
|
|
250
|
+
onUpdateSort: (index) => this._handleSortOrder({ detail: { index } }),
|
|
251
|
+
onShowExpandedContent: (index) => this._showExpandedContent(index)
|
|
252
|
+
})}
|
|
253
|
+
</div>
|
|
254
|
+
|
|
255
|
+
${renderPaginationTemplate({
|
|
256
|
+
numberOfItems: this.rowsCopy.length,
|
|
257
|
+
itemPerPage: this.itemPerPage,
|
|
258
|
+
selectedItemPerPage: this.selectedItemPerPage,
|
|
259
|
+
currentPage: this.currentPage,
|
|
260
|
+
size: this.size,
|
|
261
|
+
numberOfPages,
|
|
262
|
+
fromItem,
|
|
263
|
+
toItem,
|
|
264
|
+
enableNext,
|
|
265
|
+
enablePrevious,
|
|
266
|
+
onItemPerPageChange: (e) => this._handleItemPerPage(e),
|
|
267
|
+
onNextPage: () => {
|
|
268
|
+
this.currentPage++;
|
|
269
|
+
this._handleUpdatePage({ detail: { page: this.currentPage } });
|
|
270
|
+
},
|
|
271
|
+
onPreviousPage: () => {
|
|
272
|
+
this.currentPage--;
|
|
273
|
+
this._handleUpdatePage({ detail: { page: this.currentPage } });
|
|
274
|
+
}
|
|
275
|
+
})}
|
|
276
|
+
`;
|
|
196
277
|
}
|
|
197
278
|
};
|
|
198
279
|
HyTable.styles = styles;
|
|
@@ -203,7 +284,7 @@ __decorate([
|
|
|
203
284
|
property({ type: Array })
|
|
204
285
|
], HyTable.prototype, "rows", void 0);
|
|
205
286
|
__decorate([
|
|
206
|
-
property()
|
|
287
|
+
property({ type: String })
|
|
207
288
|
], HyTable.prototype, "size", void 0);
|
|
208
289
|
__decorate([
|
|
209
290
|
property({ type: Boolean })
|
|
@@ -212,7 +293,7 @@ __decorate([
|
|
|
212
293
|
property({ type: String })
|
|
213
294
|
], HyTable.prototype, "expandable", void 0);
|
|
214
295
|
__decorate([
|
|
215
|
-
property()
|
|
296
|
+
property({ type: String })
|
|
216
297
|
], HyTable.prototype, "selectionMode", void 0);
|
|
217
298
|
__decorate([
|
|
218
299
|
state()
|
|
@@ -238,8 +319,20 @@ __decorate([
|
|
|
238
319
|
__decorate([
|
|
239
320
|
state()
|
|
240
321
|
], HyTable.prototype, "sortAttribute", void 0);
|
|
322
|
+
__decorate([
|
|
323
|
+
state()
|
|
324
|
+
], HyTable.prototype, "expand", void 0);
|
|
325
|
+
__decorate([
|
|
326
|
+
state()
|
|
327
|
+
], HyTable.prototype, "showFilterInput", void 0);
|
|
328
|
+
__decorate([
|
|
329
|
+
state()
|
|
330
|
+
], HyTable.prototype, "filterValue", void 0);
|
|
331
|
+
__decorate([
|
|
332
|
+
query('#global-check')
|
|
333
|
+
], HyTable.prototype, "globalCheck", void 0);
|
|
241
334
|
HyTable = __decorate([
|
|
242
|
-
customElement('
|
|
335
|
+
customElement('nr-table')
|
|
243
336
|
], HyTable);
|
|
244
337
|
export { HyTable };
|
|
245
338
|
//# sourceMappingURL=table.component.js.map
|