@bento-core/paginated-table 1.0.1-icdc.17 → 1.0.1-icdc.19
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.
|
@@ -16,8 +16,7 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
|
|
|
16
16
|
const TableController = props => {
|
|
17
17
|
const {
|
|
18
18
|
tblRows,
|
|
19
|
-
table
|
|
20
|
-
onSortByColumn
|
|
19
|
+
table
|
|
21
20
|
} = props;
|
|
22
21
|
if (!tblRows) {
|
|
23
22
|
return /*#__PURE__*/_react.default.createElement(_core.Container, {
|
|
@@ -35,6 +34,12 @@ const TableController = props => {
|
|
|
35
34
|
sortBy,
|
|
36
35
|
sortOrder
|
|
37
36
|
} = table;
|
|
37
|
+
const arraySort = (a, b) => {
|
|
38
|
+
// handles sort for csvDownload column
|
|
39
|
+
const aHasData = a[sortBy] && a[sortBy].length > 0;
|
|
40
|
+
const bHasData = b[sortBy] && b[sortBy].length > 0;
|
|
41
|
+
return aHasData === bHasData ? 0 : aHasData ? -1 : 1;
|
|
42
|
+
};
|
|
38
43
|
|
|
39
44
|
/**
|
|
40
45
|
* client table aplhanumeric sorting for column table
|
|
@@ -49,12 +54,19 @@ const TableController = props => {
|
|
|
49
54
|
* sort base on table state
|
|
50
55
|
*/
|
|
51
56
|
const sortRows = (a, b) => {
|
|
57
|
+
const areValuesArrays = Array.isArray(a[sortBy]) && Array.isArray(b[sortBy]);
|
|
58
|
+
if (areValuesArrays) {
|
|
59
|
+
if (sortOrder === 'asc') {
|
|
60
|
+
return arraySort(a, b);
|
|
61
|
+
}
|
|
62
|
+
return arraySort(b, a);
|
|
63
|
+
}
|
|
52
64
|
if (sortOrder === 'asc') {
|
|
53
65
|
return alphaNumericSort(a, b);
|
|
54
66
|
}
|
|
55
67
|
return alphaNumericSort(b, a);
|
|
56
68
|
};
|
|
57
|
-
const sortedRows =
|
|
69
|
+
const sortedRows = [...updateRows].sort((a, b) => sortRows(a, b));
|
|
58
70
|
const startIndex = page * rowsPerPage;
|
|
59
71
|
const endIndex = startIndex + rowsPerPage;
|
|
60
72
|
const displayRows = [...sortedRows].slice(startIndex, endIndex);
|
|
@@ -205,7 +205,7 @@ const PaginatedTable = _ref => {
|
|
|
205
205
|
onPageChange: customizeChangePage || handleChangePage,
|
|
206
206
|
onRowSelectChange: customizeOnRowSelect || onRowSelectHandler,
|
|
207
207
|
onToggleSelectAll: customizeToggleSelectAll || handleToggleSelectAll,
|
|
208
|
-
onSortByColumn: customizeSortByColumn,
|
|
208
|
+
onSortByColumn: customizeSortByColumn || handleSortByColumn,
|
|
209
209
|
onColumnViewChange: customizeColumnViewChange || handleColumnViewChange,
|
|
210
210
|
onDeleteRow: customizeDeleteRow || onDeleteRow,
|
|
211
211
|
onDeleteAllFiles: customizeDeleteAllRows || onDeleteAllRows,
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@ import { setSelectedRows } from './TableService';
|
|
|
7
7
|
* Updates table row when table state is changed 1. (paginated action) and 2. filter action
|
|
8
8
|
*/
|
|
9
9
|
const TableController = ((props) => {
|
|
10
|
-
const { tblRows, table
|
|
10
|
+
const { tblRows, table } = props;
|
|
11
11
|
if (!tblRows) {
|
|
12
12
|
return (
|
|
13
13
|
<Container maxWidth="xl">
|
|
@@ -27,6 +27,13 @@ const TableController = ((props) => {
|
|
|
27
27
|
sortOrder,
|
|
28
28
|
} = table;
|
|
29
29
|
|
|
30
|
+
const arraySort = (a, b) => {
|
|
31
|
+
// handles sort for csvDownload column
|
|
32
|
+
const aHasData = a[sortBy] && a[sortBy].length > 0;
|
|
33
|
+
const bHasData = b[sortBy] && b[sortBy].length > 0;
|
|
34
|
+
return aHasData === bHasData ? 0 : aHasData ? -1 : 1;
|
|
35
|
+
};
|
|
36
|
+
|
|
30
37
|
/**
|
|
31
38
|
* client table aplhanumeric sorting for column table
|
|
32
39
|
* uses string prototype function for sorting
|
|
@@ -42,13 +49,20 @@ const TableController = ((props) => {
|
|
|
42
49
|
* sort base on table state
|
|
43
50
|
*/
|
|
44
51
|
const sortRows = (a, b) => {
|
|
52
|
+
const areValuesArrays = Array.isArray(a[sortBy]) && Array.isArray(b[sortBy]);
|
|
53
|
+
if (areValuesArrays) {
|
|
54
|
+
if (sortOrder === 'asc') {
|
|
55
|
+
return arraySort(a, b);
|
|
56
|
+
}
|
|
57
|
+
return arraySort(b, a);
|
|
58
|
+
}
|
|
59
|
+
|
|
45
60
|
if (sortOrder === 'asc') {
|
|
46
61
|
return alphaNumericSort(a, b);
|
|
47
62
|
}
|
|
48
63
|
return alphaNumericSort(b, a);
|
|
49
64
|
};
|
|
50
|
-
const sortedRows =
|
|
51
|
-
: [...updateRows].sort((a, b) => sortRows(a, b));
|
|
65
|
+
const sortedRows = [...updateRows].sort((a, b) => sortRows(a, b));
|
|
52
66
|
const startIndex = page * rowsPerPage;
|
|
53
67
|
const endIndex = startIndex + rowsPerPage;
|
|
54
68
|
const displayRows = [...sortedRows].slice(startIndex, endIndex);
|
|
@@ -196,7 +196,7 @@ const PaginatedTable = ({
|
|
|
196
196
|
onPageChange={customizeChangePage || handleChangePage}
|
|
197
197
|
onRowSelectChange={customizeOnRowSelect || onRowSelectHandler}
|
|
198
198
|
onToggleSelectAll={customizeToggleSelectAll || handleToggleSelectAll}
|
|
199
|
-
onSortByColumn={customizeSortByColumn}
|
|
199
|
+
onSortByColumn={customizeSortByColumn || handleSortByColumn}
|
|
200
200
|
onColumnViewChange={customizeColumnViewChange || handleColumnViewChange}
|
|
201
201
|
onDeleteRow={customizeDeleteRow || onDeleteRow}
|
|
202
202
|
onDeleteAllFiles={customizeDeleteAllRows || onDeleteAllRows}
|