es-grid-template 1.9.94 → 1.9.96
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/es/grid-component/type.d.ts +3 -1
- package/es/group-component/TableContainer.js +1 -0
- package/es/group-component/TableContainerEdit.js +1 -0
- package/es/group-component/footer/TableFooter.d.ts +2 -1
- package/es/group-component/footer/TableFooter.js +8 -11
- package/es/group-component/footer/TableFooterCell.d.ts +2 -1
- package/es/group-component/footer/TableFooterCell.js +9 -4
- package/es/group-component/footer/TableFooterRow.d.ts +2 -1
- package/es/group-component/footer/TableFooterRow.js +4 -2
- package/es/group-component/table/TableWrapper.d.ts +1 -0
- package/es/group-component/table/TableWrapper.js +4 -3
- package/es/table-component/TableContainer.js +3 -1
- package/es/table-component/TableContainerEdit.js +3 -1
- package/es/table-component/footer/TableFooter.d.ts +2 -1
- package/es/table-component/footer/TableFooter.js +8 -11
- package/es/table-component/footer/TableFooterCell.d.ts +2 -1
- package/es/table-component/footer/TableFooterCell.js +9 -4
- package/es/table-component/footer/TableFooterRow.d.ts +2 -1
- package/es/table-component/footer/TableFooterRow.js +4 -2
- package/es/table-component/table/TableWrapper.d.ts +1 -0
- package/es/table-component/table/TableWrapper.js +4 -3
- package/es/table-virtuoso/InternalTable.js +54 -11
- package/es/table-virtuoso/footer/TableFooterCell.d.ts +2 -1
- package/es/table-virtuoso/footer/TableFooterCell.js +9 -4
- package/es/table-virtuoso/table/Grid.js +37 -8
- package/es/table-virtuoso/table/TableContainer.js +3 -1
- package/es/table-virtuoso/table/TableWrapper.d.ts +1 -0
- package/es/table-virtuoso/table/TableWrapper.js +7 -7
- package/lib/grid-component/type.d.ts +3 -1
- package/lib/group-component/TableContainer.js +1 -0
- package/lib/group-component/TableContainerEdit.js +1 -0
- package/lib/group-component/footer/TableFooter.d.ts +2 -1
- package/lib/group-component/footer/TableFooter.js +8 -11
- package/lib/group-component/footer/TableFooterCell.d.ts +2 -1
- package/lib/group-component/footer/TableFooterCell.js +9 -4
- package/lib/group-component/footer/TableFooterRow.d.ts +2 -1
- package/lib/group-component/footer/TableFooterRow.js +4 -2
- package/lib/group-component/table/TableWrapper.d.ts +1 -0
- package/lib/group-component/table/TableWrapper.js +4 -3
- package/lib/table-component/TableContainer.js +3 -1
- package/lib/table-component/TableContainerEdit.js +3 -1
- package/lib/table-component/footer/TableFooter.d.ts +2 -1
- package/lib/table-component/footer/TableFooter.js +8 -11
- package/lib/table-component/footer/TableFooterCell.d.ts +2 -1
- package/lib/table-component/footer/TableFooterCell.js +9 -4
- package/lib/table-component/footer/TableFooterRow.d.ts +2 -1
- package/lib/table-component/footer/TableFooterRow.js +4 -2
- package/lib/table-component/table/TableWrapper.d.ts +1 -0
- package/lib/table-component/table/TableWrapper.js +4 -3
- package/lib/table-virtuoso/InternalTable.js +53 -10
- package/lib/table-virtuoso/footer/TableFooterCell.d.ts +2 -1
- package/lib/table-virtuoso/footer/TableFooterCell.js +9 -4
- package/lib/table-virtuoso/table/Grid.js +37 -8
- package/lib/table-virtuoso/table/TableContainer.js +3 -1
- package/lib/table-virtuoso/table/TableWrapper.d.ts +1 -0
- package/lib/table-virtuoso/table/TableWrapper.js +7 -7
- package/package.json +2 -2
|
@@ -494,7 +494,7 @@ export type TableProps<RecordType = AnyObject> = {
|
|
|
494
494
|
allowResizing?: boolean;
|
|
495
495
|
/** Hiển thị dòng tổng hợp */
|
|
496
496
|
summary?: boolean;
|
|
497
|
-
/** Dữ liệu footer */
|
|
497
|
+
/** Dữ liệu footer theo field của cột, dùng khi summary=true. Không truyền thì tự tính tổng; [] ẩn các dòng footer. */
|
|
498
498
|
footerDataSource?: any[];
|
|
499
499
|
/** Hiển thị text khi không có dữ liệu */
|
|
500
500
|
showEmptyText?: boolean;
|
|
@@ -800,6 +800,8 @@ export type SelectionSettings<T = AnyObject> = {
|
|
|
800
800
|
checkedStrategy?: 'all' | 'parent' | 'child';
|
|
801
801
|
columnWidth?: number;
|
|
802
802
|
hideSelectAll?: boolean;
|
|
803
|
+
/** When true, keep selection only for records in the current filtered data view. Default: false. */
|
|
804
|
+
pruneSelection?: boolean;
|
|
803
805
|
selectedRowKeys?: Key[];
|
|
804
806
|
defaultSelectedRowKeys?: Key[];
|
|
805
807
|
getCheckboxProps?: (record: T) => Partial<Omit<CheckboxProps, 'checked' | 'defaultChecked'>>;
|
|
@@ -2259,6 +2259,7 @@ const TableContainerEdit = props => {
|
|
|
2259
2259
|
groupColumns
|
|
2260
2260
|
}
|
|
2261
2261
|
}, /*#__PURE__*/React.createElement(TableWrapper, {
|
|
2262
|
+
footerDataSource: props.footerDataSource,
|
|
2262
2263
|
contextMenuItems: contextMenuItems,
|
|
2263
2264
|
height: tableHeight,
|
|
2264
2265
|
minHeight: minHeight,
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import type { Table } from "@tanstack/react-table";
|
|
3
3
|
interface TableFooterProps<T> {
|
|
4
4
|
table: Table<T>;
|
|
5
|
+
footerDataSource?: any[];
|
|
5
6
|
}
|
|
6
|
-
declare const TableFooter: <RecordType extends object>({ table, }: TableFooterProps<RecordType>) => JSX.Element;
|
|
7
|
+
declare const TableFooter: <RecordType extends object>({ table, footerDataSource, }: TableFooterProps<RecordType>) => JSX.Element;
|
|
7
8
|
export default TableFooter;
|
|
@@ -4,7 +4,8 @@ import { TableContext } from "../useContext";
|
|
|
4
4
|
import React, { useContext } from "react";
|
|
5
5
|
const TableFooter = ({
|
|
6
6
|
// columnVirtualizer,
|
|
7
|
-
table
|
|
7
|
+
table,
|
|
8
|
+
footerDataSource
|
|
8
9
|
// virtualPaddingLeft,
|
|
9
10
|
// virtualPaddingRight,
|
|
10
11
|
// ...rest
|
|
@@ -20,15 +21,11 @@ const TableFooter = ({
|
|
|
20
21
|
bottom: 0,
|
|
21
22
|
zIndex: 1
|
|
22
23
|
}
|
|
23
|
-
}, /*#__PURE__*/React.createElement(TableFooterRow, {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// virtualPaddingLeft={virtualPaddingLeft}
|
|
30
|
-
// virtualPaddingRight={virtualPaddingRight}
|
|
31
|
-
// {...rest}
|
|
32
|
-
}));
|
|
24
|
+
}, (footerDataSource ?? [undefined]).map((footerRow, index) => /*#__PURE__*/React.createElement(TableFooterRow, {
|
|
25
|
+
key: index,
|
|
26
|
+
table: table,
|
|
27
|
+
headerGroup: table.getHeaderGroups()[table.getHeaderGroups().length - 1],
|
|
28
|
+
footerRow: footerRow
|
|
29
|
+
})));
|
|
33
30
|
};
|
|
34
31
|
export default TableFooter;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import type { Column } from "@tanstack/react-table";
|
|
3
3
|
interface TableFooterCellProps<T> {
|
|
4
4
|
column: Column<T, any>;
|
|
5
|
+
footerRow?: Record<string, any>;
|
|
5
6
|
}
|
|
6
|
-
declare const TableFooterCell: <RecordType extends object>({ column }: TableFooterCellProps<RecordType>) => JSX.Element;
|
|
7
|
+
declare const TableFooterCell: <RecordType extends object>({ column, footerRow }: TableFooterCellProps<RecordType>) => JSX.Element;
|
|
7
8
|
export default TableFooterCell;
|
|
@@ -5,7 +5,8 @@ import classNames from "classnames";
|
|
|
5
5
|
import { sumByField } from "../../grid-component/hooks";
|
|
6
6
|
import { numericFormatter } from "react-numeric-component";
|
|
7
7
|
const TableFooterCell = ({
|
|
8
|
-
column
|
|
8
|
+
column,
|
|
9
|
+
footerRow
|
|
9
10
|
}) => {
|
|
10
11
|
const isPinned = column.getIsPinned();
|
|
11
12
|
const isLastLeftPinnedColumn = isPinned === 'left' && column.getIsLastColumn('left');
|
|
@@ -16,7 +17,10 @@ const TableFooterCell = ({
|
|
|
16
17
|
dataSource
|
|
17
18
|
} = useContext(TableContext);
|
|
18
19
|
const col = column.columnDef.meta ?? {};
|
|
19
|
-
const
|
|
20
|
+
const isCustomFooter = footerRow !== undefined;
|
|
21
|
+
const field = col.field;
|
|
22
|
+
const hasFooterValue = isCustomFooter && Object.prototype.hasOwnProperty.call(footerRow, field) && footerRow[field] != null;
|
|
23
|
+
const colFormat = typeof col.format === 'function' ? col.format(footerRow ?? {}) : col.format;
|
|
20
24
|
const cellFormat = getFormat(colFormat, format);
|
|
21
25
|
const thousandSeparator = cellFormat?.thousandSeparator;
|
|
22
26
|
const decimalSeparator = cellFormat?.decimalSeparator;
|
|
@@ -25,7 +29,7 @@ const TableFooterCell = ({
|
|
|
25
29
|
const dec = cellFormat?.decimalScale;
|
|
26
30
|
|
|
27
31
|
// const sumValue = col.type === 'number' ? sumDataByField(filterDataByColumns4(dataSource, filterStates) as any[], col?.key as string) : 0
|
|
28
|
-
const sumValue = col.type === 'number' ? sumByField(dataSource,
|
|
32
|
+
const sumValue = col.type === 'number' ? isCustomFooter ? hasFooterValue ? Number(footerRow[field]) : 0 : sumByField(dataSource, field) : 0;
|
|
29
33
|
const value = !isEmpty(sumValue) ? dec || dec === 0 ? parseFloat(Number(sumValue).toFixed(dec)).toString() : sumValue.toString() : '0';
|
|
30
34
|
const cellValue = col.type === 'number' && col.isSummary !== false ? value : '';
|
|
31
35
|
const numberValue = Number(value);
|
|
@@ -38,6 +42,7 @@ const TableFooterCell = ({
|
|
|
38
42
|
decimalScale: dec,
|
|
39
43
|
fixedDecimalScale: cellFormat?.fixedDecimalScale ?? false
|
|
40
44
|
};
|
|
45
|
+
const content = isCustomFooter && (!hasFooterValue || col.isSummary === false) ? '' : col.summaryTemplate ? col.summaryTemplate(numberValue, field) : isCustomFooter && col.type !== 'number' ? footerRow[field] : numericFormatter(cellValue, numericFormatProps);
|
|
41
46
|
return /*#__PURE__*/React.createElement("div", {
|
|
42
47
|
// ref={el => {
|
|
43
48
|
// if (el) columnVirtualizer.measureElement(el)
|
|
@@ -61,6 +66,6 @@ const TableFooterCell = ({
|
|
|
61
66
|
minWidth: column?.getSize()
|
|
62
67
|
// backgroundColor: "#fafafa",
|
|
63
68
|
}
|
|
64
|
-
}, column.id !== "id" && column.id !== "selection_column" ? /*#__PURE__*/React.createElement(React.Fragment, null,
|
|
69
|
+
}, column.id !== "id" && column.id !== "selection_column" ? /*#__PURE__*/React.createElement(React.Fragment, null, content) : '');
|
|
65
70
|
};
|
|
66
71
|
export default TableFooterCell;
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
import type { HeaderGroup, Table } from "@tanstack/react-table";
|
|
3
3
|
interface TableFooterRowProps<T> {
|
|
4
4
|
table: Table<T>;
|
|
5
|
+
footerRow?: Record<string, any>;
|
|
5
6
|
headerGroup: HeaderGroup<T>;
|
|
6
7
|
}
|
|
7
|
-
declare const TableFooterRow: <RecordType extends object>({ table, headerGroup, }: TableFooterRowProps<RecordType>) => JSX.Element;
|
|
8
|
+
declare const TableFooterRow: <RecordType extends object>({ table, headerGroup, footerRow, }: TableFooterRowProps<RecordType>) => JSX.Element;
|
|
8
9
|
export default TableFooterRow;
|
|
@@ -3,7 +3,8 @@ import React from "react";
|
|
|
3
3
|
import { TableContext } from "../useContext";
|
|
4
4
|
const TableFooterRow = ({
|
|
5
5
|
table,
|
|
6
|
-
headerGroup
|
|
6
|
+
headerGroup,
|
|
7
|
+
footerRow
|
|
7
8
|
}) => {
|
|
8
9
|
const visibleColumns = table.getVisibleLeafColumns();
|
|
9
10
|
const {
|
|
@@ -23,7 +24,8 @@ const TableFooterRow = ({
|
|
|
23
24
|
}, visibleColumns.map(header => {
|
|
24
25
|
return /*#__PURE__*/React.createElement(TableFooterCell, {
|
|
25
26
|
key: header.id,
|
|
26
|
-
column: header
|
|
27
|
+
column: header,
|
|
28
|
+
footerRow: footerRow
|
|
27
29
|
});
|
|
28
30
|
}));
|
|
29
31
|
};
|
|
@@ -232,9 +232,10 @@ const TableWrapper = props => {
|
|
|
232
232
|
virtualPaddingRight: virtualPaddingRight,
|
|
233
233
|
fixedLeftColumns: fixedLeftColumns,
|
|
234
234
|
fixedRightColumns: fixedRightColumns
|
|
235
|
-
}), summary && /*#__PURE__*/React.createElement(TableFooter
|
|
236
|
-
|
|
237
|
-
|
|
235
|
+
}), summary && /*#__PURE__*/React.createElement(TableFooter, {
|
|
236
|
+
footerDataSource: props.footerDataSource
|
|
237
|
+
// columnVirtualizer={columnVirtualizer}
|
|
238
|
+
,
|
|
238
239
|
table: table
|
|
239
240
|
// virtualPaddingLeft={virtualPaddingLeft}
|
|
240
241
|
// virtualPaddingRight={virtualPaddingRight}
|
|
@@ -350,7 +350,9 @@ const TableContainer = props => {
|
|
|
350
350
|
setIsExpandClick,
|
|
351
351
|
maxDepth
|
|
352
352
|
}
|
|
353
|
-
}, /*#__PURE__*/React.createElement(TableWrapper, _extends({
|
|
353
|
+
}, /*#__PURE__*/React.createElement(TableWrapper, _extends({
|
|
354
|
+
footerDataSource: props.footerDataSource
|
|
355
|
+
}, rest, {
|
|
354
356
|
contextMenuItems: contextMenuItems,
|
|
355
357
|
height: tableHeight,
|
|
356
358
|
minHeight: minHeight,
|
|
@@ -2277,7 +2277,9 @@ const TableContainerEdit = props => {
|
|
|
2277
2277
|
setIsExpandClick,
|
|
2278
2278
|
isAddAble
|
|
2279
2279
|
}
|
|
2280
|
-
}, /*#__PURE__*/React.createElement(TableWrapper, _extends({
|
|
2280
|
+
}, /*#__PURE__*/React.createElement(TableWrapper, _extends({
|
|
2281
|
+
footerDataSource: props.footerDataSource
|
|
2282
|
+
}, rest, {
|
|
2281
2283
|
contextMenuItems: contextMenuItems,
|
|
2282
2284
|
height: tableHeight,
|
|
2283
2285
|
minHeight: minHeight,
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import type { Table } from "@tanstack/react-table";
|
|
3
3
|
interface TableFooterProps<T> {
|
|
4
4
|
table: Table<T>;
|
|
5
|
+
footerDataSource?: any[];
|
|
5
6
|
}
|
|
6
|
-
declare const TableFooter: <RecordType extends object>({ table, }: TableFooterProps<RecordType>) => JSX.Element;
|
|
7
|
+
declare const TableFooter: <RecordType extends object>({ table, footerDataSource, }: TableFooterProps<RecordType>) => JSX.Element;
|
|
7
8
|
export default TableFooter;
|
|
@@ -4,7 +4,8 @@ import { TableContext } from "../useContext";
|
|
|
4
4
|
import React, { useContext } from "react";
|
|
5
5
|
const TableFooter = ({
|
|
6
6
|
// columnVirtualizer,
|
|
7
|
-
table
|
|
7
|
+
table,
|
|
8
|
+
footerDataSource
|
|
8
9
|
// virtualPaddingLeft,
|
|
9
10
|
// virtualPaddingRight,
|
|
10
11
|
// ...rest
|
|
@@ -20,15 +21,11 @@ const TableFooter = ({
|
|
|
20
21
|
bottom: 0,
|
|
21
22
|
zIndex: 1
|
|
22
23
|
}
|
|
23
|
-
}, /*#__PURE__*/React.createElement(TableFooterRow, {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// virtualPaddingLeft={virtualPaddingLeft}
|
|
30
|
-
// virtualPaddingRight={virtualPaddingRight}
|
|
31
|
-
// {...rest}
|
|
32
|
-
}));
|
|
24
|
+
}, (footerDataSource ?? [undefined]).map((footerRow, index) => /*#__PURE__*/React.createElement(TableFooterRow, {
|
|
25
|
+
key: index,
|
|
26
|
+
table: table,
|
|
27
|
+
headerGroup: table.getHeaderGroups()[table.getHeaderGroups().length - 1],
|
|
28
|
+
footerRow: footerRow
|
|
29
|
+
})));
|
|
33
30
|
};
|
|
34
31
|
export default TableFooter;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import type { Column } from "@tanstack/react-table";
|
|
3
3
|
interface TableFooterCellProps<T> {
|
|
4
4
|
column: Column<T, any>;
|
|
5
|
+
footerRow?: Record<string, any>;
|
|
5
6
|
}
|
|
6
|
-
declare const TableFooterCell: <RecordType extends object>({ column }: TableFooterCellProps<RecordType>) => JSX.Element;
|
|
7
|
+
declare const TableFooterCell: <RecordType extends object>({ column, footerRow }: TableFooterCellProps<RecordType>) => JSX.Element;
|
|
7
8
|
export default TableFooterCell;
|
|
@@ -5,7 +5,8 @@ import classNames from "classnames";
|
|
|
5
5
|
import { sumByField } from "../../grid-component/hooks";
|
|
6
6
|
import { numericFormatter } from "react-numeric-component";
|
|
7
7
|
const TableFooterCell = ({
|
|
8
|
-
column
|
|
8
|
+
column,
|
|
9
|
+
footerRow
|
|
9
10
|
}) => {
|
|
10
11
|
const isPinned = column.getIsPinned();
|
|
11
12
|
const isLastLeftPinnedColumn = isPinned === 'left' && column.getIsLastColumn('left');
|
|
@@ -16,7 +17,10 @@ const TableFooterCell = ({
|
|
|
16
17
|
dataSource
|
|
17
18
|
} = useContext(TableContext);
|
|
18
19
|
const col = column.columnDef.meta ?? {};
|
|
19
|
-
const
|
|
20
|
+
const isCustomFooter = footerRow !== undefined;
|
|
21
|
+
const field = col.field;
|
|
22
|
+
const hasFooterValue = isCustomFooter && Object.prototype.hasOwnProperty.call(footerRow, field) && footerRow[field] != null;
|
|
23
|
+
const colFormat = typeof col.format === 'function' ? col.format(footerRow ?? {}) : col.format;
|
|
20
24
|
const cellFormat = getFormat(colFormat, format);
|
|
21
25
|
const thousandSeparator = cellFormat?.thousandSeparator;
|
|
22
26
|
const decimalSeparator = cellFormat?.decimalSeparator;
|
|
@@ -25,7 +29,7 @@ const TableFooterCell = ({
|
|
|
25
29
|
const dec = cellFormat?.decimalScale;
|
|
26
30
|
|
|
27
31
|
// const sumValue = col.type === 'number' ? sumDataByField(filterDataByColumns4(dataSource, filterStates) as any[], col?.key as string) : 0
|
|
28
|
-
const sumValue = col.type === 'number' ? sumByField(dataSource,
|
|
32
|
+
const sumValue = col.type === 'number' ? isCustomFooter ? hasFooterValue ? Number(footerRow[field]) : 0 : sumByField(dataSource, field) : 0;
|
|
29
33
|
const value = !isEmpty(sumValue) ? dec || dec === 0 ? parseFloat(Number(sumValue).toFixed(dec)).toString() : sumValue.toString() : '0';
|
|
30
34
|
const cellValue = col.type === 'number' && col.isSummary !== false ? value : '';
|
|
31
35
|
const numberValue = Number(value);
|
|
@@ -38,6 +42,7 @@ const TableFooterCell = ({
|
|
|
38
42
|
decimalScale: dec,
|
|
39
43
|
fixedDecimalScale: cellFormat?.fixedDecimalScale ?? false
|
|
40
44
|
};
|
|
45
|
+
const content = isCustomFooter && (!hasFooterValue || col.isSummary === false) ? '' : col.summaryTemplate ? col.summaryTemplate(numberValue, field) : isCustomFooter && col.type !== 'number' ? footerRow[field] : numericFormatter(cellValue, numericFormatProps);
|
|
41
46
|
return /*#__PURE__*/React.createElement("div", {
|
|
42
47
|
// ref={el => {
|
|
43
48
|
// if (el) columnVirtualizer.measureElement(el)
|
|
@@ -61,6 +66,6 @@ const TableFooterCell = ({
|
|
|
61
66
|
minWidth: column?.getSize()
|
|
62
67
|
// backgroundColor: "#fafafa",
|
|
63
68
|
}
|
|
64
|
-
}, column.id !== "id" && column.id !== "selection_column" ? /*#__PURE__*/React.createElement(React.Fragment, null,
|
|
69
|
+
}, column.id !== "id" && column.id !== "selection_column" ? /*#__PURE__*/React.createElement(React.Fragment, null, content) : '');
|
|
65
70
|
};
|
|
66
71
|
export default TableFooterCell;
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
import type { HeaderGroup, Table } from "@tanstack/react-table";
|
|
3
3
|
interface TableFooterRowProps<T> {
|
|
4
4
|
table: Table<T>;
|
|
5
|
+
footerRow?: Record<string, any>;
|
|
5
6
|
headerGroup: HeaderGroup<T>;
|
|
6
7
|
}
|
|
7
|
-
declare const TableFooterRow: <RecordType extends object>({ table, headerGroup, }: TableFooterRowProps<RecordType>) => JSX.Element;
|
|
8
|
+
declare const TableFooterRow: <RecordType extends object>({ table, headerGroup, footerRow, }: TableFooterRowProps<RecordType>) => JSX.Element;
|
|
8
9
|
export default TableFooterRow;
|
|
@@ -3,7 +3,8 @@ import React from "react";
|
|
|
3
3
|
import { TableContext } from "../useContext";
|
|
4
4
|
const TableFooterRow = ({
|
|
5
5
|
table,
|
|
6
|
-
headerGroup
|
|
6
|
+
headerGroup,
|
|
7
|
+
footerRow
|
|
7
8
|
}) => {
|
|
8
9
|
const visibleColumns = table.getVisibleLeafColumns();
|
|
9
10
|
const {
|
|
@@ -23,7 +24,8 @@ const TableFooterRow = ({
|
|
|
23
24
|
}, visibleColumns.map(header => {
|
|
24
25
|
return /*#__PURE__*/React.createElement(TableFooterCell, {
|
|
25
26
|
key: header.id,
|
|
26
|
-
column: header
|
|
27
|
+
column: header,
|
|
28
|
+
footerRow: footerRow
|
|
27
29
|
});
|
|
28
30
|
}));
|
|
29
31
|
};
|
|
@@ -285,9 +285,10 @@ const TableWrapper = props => {
|
|
|
285
285
|
virtualPaddingRight: virtualPaddingRight,
|
|
286
286
|
fixedLeftColumns: fixedLeftColumns,
|
|
287
287
|
fixedRightColumns: fixedRightColumns
|
|
288
|
-
}), summary && /*#__PURE__*/React.createElement(TableFooter
|
|
289
|
-
|
|
290
|
-
|
|
288
|
+
}), summary && /*#__PURE__*/React.createElement(TableFooter, {
|
|
289
|
+
footerDataSource: props.footerDataSource
|
|
290
|
+
// columnVirtualizer={columnVirtualizer}
|
|
291
|
+
,
|
|
291
292
|
table: table
|
|
292
293
|
// virtualPaddingLeft={virtualPaddingLeft}
|
|
293
294
|
// virtualPaddingRight={virtualPaddingRight}
|
|
@@ -8,7 +8,7 @@ import 'dayjs/locale/vi';
|
|
|
8
8
|
import { faker } from '@faker-js/faker';
|
|
9
9
|
import useMergedState from "rc-util/es/hooks/useMergedState";
|
|
10
10
|
import { getCoreRowModel, getExpandedRowModel, getGroupedRowModel, getPaginationRowModel, useReactTable } from '@tanstack/react-table';
|
|
11
|
-
import { addRowIdArray, convertFlatColumn1, convertToObj, convertToObjTrue, filterDataByColumns, findAllChildrenKeys2, flatColumns2, getAllRowKey, getDiffent2Array, getFixedFields, getInvisibleColumns, groupArrayByColumns, isTreeArray, removeKeys } from "./hook/utils";
|
|
11
|
+
import { addRowIdArray, convertFlatColumn1, convertToObj, convertToObjTrue, filterDataByColumns, findAllChildrenKeys2, flattenArray, flattenData, flatColumns2, getAllRowKey, getDiffent2Array, getFixedFields, getInvisibleColumns, groupArrayByColumns, isTreeArray, removeKeys } from "./hook/utils";
|
|
12
12
|
// import { convertToTanStackColumns } from './hook/useColumns'
|
|
13
13
|
import { removeInvisibleColumns } from "../grid-component/hooks";
|
|
14
14
|
import Grid from "./table/Grid";
|
|
@@ -82,6 +82,7 @@ const InternalTable = props => {
|
|
|
82
82
|
const [columnResizeMode] = React.useState('onChange');
|
|
83
83
|
const [columnResizeDirection] = React.useState('ltr');
|
|
84
84
|
const [rowSelection, setRowSelection] = React.useState({});
|
|
85
|
+
const pruneSelection = selectionSettings?.pruneSelection === true;
|
|
85
86
|
|
|
86
87
|
// const [grouping, setGrouping] = React.useState<GroupingState>([])
|
|
87
88
|
|
|
@@ -118,6 +119,9 @@ const InternalTable = props => {
|
|
|
118
119
|
return isTreeArray(originData);
|
|
119
120
|
}, [originData]);
|
|
120
121
|
React.useEffect(() => {
|
|
122
|
+
if (pruneSelection) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
121
125
|
if (groupColumns && groupColumns.length > 0 && groupSetting?.client !== false && isDataOriginTree === false) {
|
|
122
126
|
const abc = groupArrayByColumns(originData, groupColumns);
|
|
123
127
|
const rs = filterDataByColumns(abc, filterStates, sorterStates, []);
|
|
@@ -126,9 +130,48 @@ const InternalTable = props => {
|
|
|
126
130
|
const rs = filterDataByColumns(originData, filterStates, sorterStates, []);
|
|
127
131
|
setTableData(rs);
|
|
128
132
|
}
|
|
129
|
-
}, [groupColumns, originData, filterStates, sorterStates, groupSetting?.client, isDataOriginTree]);
|
|
133
|
+
}, [groupColumns, originData, filterStates, sorterStates, groupSetting?.client, isDataOriginTree, pruneSelection]);
|
|
130
134
|
// }, [groupColumns, originData, filterStates, sorterStates, groupSetting?.client])
|
|
131
135
|
|
|
136
|
+
// Resolve the opt-in view before paint, including inline grouping arrays.
|
|
137
|
+
const groupColumnsKey = JSON.stringify(groupColumns ?? []);
|
|
138
|
+
const viewData = React.useMemo(() => {
|
|
139
|
+
if (!pruneSelection) {
|
|
140
|
+
return tableData;
|
|
141
|
+
}
|
|
142
|
+
const groups = JSON.parse(groupColumnsKey);
|
|
143
|
+
const grouped = groups.length && groupSetting?.client !== false && !isDataOriginTree ? groupArrayByColumns(originData, groups) : originData;
|
|
144
|
+
return filterDataByColumns(grouped, filterStates, sorterStates, []);
|
|
145
|
+
}, [pruneSelection, tableData, groupColumnsKey, originData, groupSetting?.client, isDataOriginTree, filterStates, sorterStates]);
|
|
146
|
+
const effectiveRowSelection = React.useMemo(() => {
|
|
147
|
+
if (!pruneSelection || props.loading) {
|
|
148
|
+
return rowSelection;
|
|
149
|
+
}
|
|
150
|
+
const ids = new Set(flattenArray(viewData).map(row => String(row.rowId)));
|
|
151
|
+
const next = Object.fromEntries(Object.entries(rowSelection).filter(([selectedId, checked]) => checked && ids.has(selectedId)));
|
|
152
|
+
|
|
153
|
+
// A group can stay checked only if its remaining real children are checked.
|
|
154
|
+
const checkGroups = rows => {
|
|
155
|
+
rows.forEach(row => {
|
|
156
|
+
if (row.isGroupRow && next[String(row.rowId)]) {
|
|
157
|
+
const children = flattenData('children', row.children ?? []).filter(child => !child.isGroupRow && !selectionSettings?.getCheckboxProps?.(child)?.disabled);
|
|
158
|
+
if (!children.length || children.some(child => !next[String(child.rowId)])) {
|
|
159
|
+
delete next[String(row.rowId)];
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (Array.isArray(row.children)) {
|
|
163
|
+
checkGroups(row.children);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
checkGroups(viewData);
|
|
168
|
+
return Object.keys(next).length === Object.keys(rowSelection).length ? rowSelection : next;
|
|
169
|
+
}, [pruneSelection, props.loading, rowSelection, viewData, selectionSettings?.getCheckboxProps]);
|
|
170
|
+
React.useEffect(() => {
|
|
171
|
+
if (effectiveRowSelection !== rowSelection) {
|
|
172
|
+
setRowSelection(prev => prev === rowSelection ? effectiveRowSelection : prev);
|
|
173
|
+
}
|
|
174
|
+
}, [effectiveRowSelection, rowSelection]);
|
|
132
175
|
React.useEffect(() => {
|
|
133
176
|
// setColumns(updateWidthsByOther(propsColumns, columns))
|
|
134
177
|
setColumns(propsColumns);
|
|
@@ -142,8 +185,8 @@ const InternalTable = props => {
|
|
|
142
185
|
});
|
|
143
186
|
}, [t, columns, format, editAble]);
|
|
144
187
|
const isDataTree = React.useMemo(() => {
|
|
145
|
-
return isTreeArray(
|
|
146
|
-
}, [
|
|
188
|
+
return isTreeArray(viewData);
|
|
189
|
+
}, [viewData]);
|
|
147
190
|
const columnPinning = React.useMemo(() => {
|
|
148
191
|
return {
|
|
149
192
|
left: getFixedFields(columns, 'left'),
|
|
@@ -203,11 +246,11 @@ const InternalTable = props => {
|
|
|
203
246
|
};
|
|
204
247
|
const table = useReactTable({
|
|
205
248
|
_features: [OperatorFeature],
|
|
206
|
-
data:
|
|
249
|
+
data: viewData,
|
|
207
250
|
// data: mergedData,
|
|
208
251
|
columns: mergedColumns,
|
|
209
252
|
state: {
|
|
210
|
-
rowSelection,
|
|
253
|
+
rowSelection: effectiveRowSelection,
|
|
211
254
|
expanded,
|
|
212
255
|
columnPinning,
|
|
213
256
|
columnVisibility: columnsHiddenKeys ? convertToObj(columnsHiddenKeys) : columnVisibility,
|
|
@@ -282,20 +325,20 @@ const InternalTable = props => {
|
|
|
282
325
|
React.useEffect(() => {
|
|
283
326
|
if (expandable?.preserveExpandedOnDataChange) {
|
|
284
327
|
// Chờ cây có dữ liệu mới khởi tạo; những lần thay đổi tableData sau đó không reset expanded.
|
|
285
|
-
if (initializedExpansionRef.current ||
|
|
328
|
+
if (initializedExpansionRef.current || viewData.length === 0) {
|
|
286
329
|
return;
|
|
287
330
|
}
|
|
288
331
|
initializedExpansionRef.current = true;
|
|
289
332
|
}
|
|
290
333
|
if (defaultExpandAllRows) {
|
|
291
|
-
const allKeys = findAllChildrenKeys2(
|
|
334
|
+
const allKeys = findAllChildrenKeys2(viewData, rowKey, 'children');
|
|
292
335
|
setExpanded(convertToObjTrue(allKeys));
|
|
293
336
|
} else {
|
|
294
337
|
if (defaultExpandedRowKeys) {
|
|
295
338
|
setExpanded(convertToObjTrue(defaultExpandedRowKeys ?? []));
|
|
296
339
|
}
|
|
297
340
|
}
|
|
298
|
-
}, [defaultExpandAllRows, defaultExpandedRowKeys,
|
|
341
|
+
}, [defaultExpandAllRows, defaultExpandedRowKeys, viewData, expandable?.preserveExpandedOnDataChange]);
|
|
299
342
|
const triggerGroupColumns = groupedColumns => {
|
|
300
343
|
// const abc = updateColumnsByGroup(columns, groupedColumns)
|
|
301
344
|
|
|
@@ -382,7 +425,7 @@ const InternalTable = props => {
|
|
|
382
425
|
originData: originData
|
|
383
426
|
// dataSource={mergedData}
|
|
384
427
|
,
|
|
385
|
-
dataSource:
|
|
428
|
+
dataSource: viewData,
|
|
386
429
|
locale: locale,
|
|
387
430
|
format: format
|
|
388
431
|
// columns={convertColumns(mergedColumns)}
|
|
@@ -417,7 +460,7 @@ const InternalTable = props => {
|
|
|
417
460
|
columnSizing: columnSizing,
|
|
418
461
|
columnSizingInfo: columnSizingInfo,
|
|
419
462
|
setColumnSizing: setColumnSizing,
|
|
420
|
-
rowSelection:
|
|
463
|
+
rowSelection: effectiveRowSelection,
|
|
421
464
|
pagination: pagination
|
|
422
465
|
})))));
|
|
423
466
|
};
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import type { Column } from "@tanstack/react-table";
|
|
3
3
|
interface TableFooterCellProps<T> {
|
|
4
4
|
column: Column<T, any>;
|
|
5
|
+
footerRow?: Record<string, any>;
|
|
5
6
|
}
|
|
6
|
-
declare const TableFooterCell: <RecordType extends object>({ column }: TableFooterCellProps<RecordType>) => JSX.Element;
|
|
7
|
+
declare const TableFooterCell: <RecordType extends object>({ column, footerRow }: TableFooterCellProps<RecordType>) => JSX.Element;
|
|
7
8
|
export default TableFooterCell;
|
|
@@ -5,7 +5,8 @@ import classNames from "classnames";
|
|
|
5
5
|
import { sumByField } from "../../grid-component/hooks";
|
|
6
6
|
import { numericFormatter } from "react-numeric-component";
|
|
7
7
|
const TableFooterCell = ({
|
|
8
|
-
column
|
|
8
|
+
column,
|
|
9
|
+
footerRow
|
|
9
10
|
}) => {
|
|
10
11
|
const {
|
|
11
12
|
prefix,
|
|
@@ -13,7 +14,10 @@ const TableFooterCell = ({
|
|
|
13
14
|
dataSource
|
|
14
15
|
} = useContext(TableContext);
|
|
15
16
|
const col = column.columnDef.meta ?? {};
|
|
16
|
-
const
|
|
17
|
+
const isCustomFooter = footerRow !== undefined;
|
|
18
|
+
const field = col.field;
|
|
19
|
+
const hasFooterValue = isCustomFooter && Object.prototype.hasOwnProperty.call(footerRow, field) && footerRow[field] != null;
|
|
20
|
+
const colFormat = typeof col.format === 'function' ? col.format(footerRow ?? {}) : col.format;
|
|
17
21
|
const cellFormat = getFormat(colFormat, format);
|
|
18
22
|
const thousandSeparator = cellFormat?.thousandSeparator;
|
|
19
23
|
const decimalSeparator = cellFormat?.decimalSeparator;
|
|
@@ -22,7 +26,7 @@ const TableFooterCell = ({
|
|
|
22
26
|
const dec = cellFormat?.decimalScale;
|
|
23
27
|
|
|
24
28
|
// const sumValue = col.type === 'number' ? sumDataByField(filterDataByColumns4(dataSource, filterStates) as any[], col?.key as string) : 0
|
|
25
|
-
const sumValue = col.type === 'number' ? sumByField(dataSource,
|
|
29
|
+
const sumValue = col.type === 'number' ? isCustomFooter ? hasFooterValue ? Number(footerRow[field]) : 0 : sumByField(dataSource, field) : 0;
|
|
26
30
|
const value = !isEmpty(sumValue) ? dec || dec === 0 ? parseFloat(Number(sumValue).toFixed(dec)).toString() : sumValue.toString() : '0';
|
|
27
31
|
const cellValue = col.type === 'number' && col.isSummary !== false ? value : '';
|
|
28
32
|
const numberValue = Number(value);
|
|
@@ -35,6 +39,7 @@ const TableFooterCell = ({
|
|
|
35
39
|
decimalScale: dec,
|
|
36
40
|
fixedDecimalScale: cellFormat?.fixedDecimalScale ?? false
|
|
37
41
|
};
|
|
42
|
+
const content = isCustomFooter && (!hasFooterValue || col.isSummary === false) ? '' : col.summaryTemplate ? col.summaryTemplate(numberValue, field) : isCustomFooter && col.type !== 'number' ? footerRow[field] : numericFormatter(cellValue, numericFormatProps);
|
|
38
43
|
return /*#__PURE__*/React.createElement("th", {
|
|
39
44
|
className: classNames(`${prefix}-grid-cell`, {
|
|
40
45
|
// [`${prefix}-grid-cell-fix-left-last`]: isLastLeftPinnedColumn,
|
|
@@ -49,6 +54,6 @@ const TableFooterCell = ({
|
|
|
49
54
|
minWidth: column?.getSize(),
|
|
50
55
|
height: 40
|
|
51
56
|
}
|
|
52
|
-
}, column.id !== "id" && column.id !== "selection_column" ? /*#__PURE__*/React.createElement(React.Fragment, null,
|
|
57
|
+
}, column.id !== "id" && column.id !== "selection_column" ? /*#__PURE__*/React.createElement(React.Fragment, null, content) : '');
|
|
53
58
|
};
|
|
54
59
|
export default TableFooterCell;
|