es-grid-template 1.9.82 → 1.9.83

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.
@@ -76,6 +76,8 @@ export type Locale = {
76
76
  export type PaginationConfig = Omit<TablePaginationConfig, 'locale' | 'current'> & {
77
77
  currentPage?: number;
78
78
  locale?: PagingLocale;
79
+ /** Chế độ phân trang. Mặc định là client để giữ tương thích với hành vi hiện tại. */
80
+ mode?: 'client' | 'server';
79
81
  };
80
82
  export type AnyObject = Record<PropertyKey, any>;
81
83
  export type IFormat = {
@@ -6,7 +6,6 @@ import moment from "moment";
6
6
  export const newGuid = () => {
7
7
  for (let i = 0; i < 20; i++) {
8
8
  // @ts-ignore
9
- // const id = crypto.randomUUID()
10
9
  return uuidv4();
11
10
  }
12
11
  };
@@ -6,7 +6,6 @@ import { nonActionColumn } from "../../grid-component/hooks";
6
6
  export const newGuid = () => {
7
7
  for (let i = 0; i < 20; i++) {
8
8
  // @ts-ignore
9
- // const id = crypto.randomUUID()
10
9
  return uuidv4();
11
10
  }
12
11
  };
@@ -89,6 +89,8 @@ const InternalTable = props => {
89
89
  pageIndex: pagination && pagination.currentPage ? pagination.currentPage - 1 : 0,
90
90
  pageSize: pagination && pagination.pageSize ? pagination.pageSize : 20
91
91
  });
92
+ const isServerPagination = Boolean(pagination && pagination.mode === 'server');
93
+ const shouldUseClientPagination = Boolean(pagination) && !infiniteScroll && !isServerPagination;
92
94
  const [columnSizing, setColumnSizing] = React.useState({});
93
95
  const [columnSizingInfo, setColumnSizingInfo] = React.useState({});
94
96
 
@@ -264,7 +266,10 @@ const InternalTable = props => {
264
266
  getGroupedRowModel: getGroupedRowModel(),
265
267
  // onExpandedChange: setExpanded,
266
268
  getExpandedRowModel: getExpandedRowModel(),
267
- getPaginationRowModel: pagination && !infiniteScroll ? getPaginationRowModel() : undefined,
269
+ manualPagination: isServerPagination,
270
+ // Chỉ để TanStack tự phân trang khi có pagination, không dùng infinite scroll và đang ở chế độ client.
271
+ // Với server pagination, dữ liệu đã được BE phân trang nên không chạy getPaginationRowModel() để tránh phân trang lần 2.
272
+ getPaginationRowModel: shouldUseClientPagination ? getPaginationRowModel() : undefined,
268
273
  onPaginationChange: setPagination,
269
274
  onColumnVisibilityChange: setColumnVisibility
270
275
  // onColumnPinningChange,
@@ -79,6 +79,16 @@ const TableContainer = props => {
79
79
  } = props;
80
80
  const [paginationLocal] = useLocale('Pagination');
81
81
  const [tableLocal] = useLocale('Table');
82
+ const paginationProps = React.useMemo(() => {
83
+ if (!pagination) {
84
+ return undefined;
85
+ }
86
+ const paginationConfig = {
87
+ ...pagination
88
+ };
89
+ delete paginationConfig.mode;
90
+ return paginationConfig;
91
+ }, [pagination]);
82
92
  const tableContainerRef = React.useRef(null);
83
93
  const containerRef = React.useRef(null);
84
94
  const bottomToolbarRef = React.useRef(null);
@@ -210,7 +220,7 @@ const TableContainer = props => {
210
220
  showTotal: (totalItems, range) =>
211
221
  // @ts-ignore
212
222
  `${range[0]}-${range[1]} / ${totalItems} ${t ? t(pagination?.locale?.items ?? 'items') : 'items'}`
213
- }, pagination)), typeof actionTemplate === 'function' ? actionTemplate() : actionTemplate, toolbarItemTopRight && /*#__PURE__*/React.createElement("div", {
223
+ }, paginationProps)), typeof actionTemplate === 'function' ? actionTemplate() : actionTemplate, toolbarItemTopRight && /*#__PURE__*/React.createElement("div", {
214
224
  style: {
215
225
  flex: 1,
216
226
  overflow: 'hidden'
@@ -299,7 +309,7 @@ const TableContainer = props => {
299
309
  })} / ${numericFormatter((totalItems ?? 0).toString(), {
300
310
  thousandSeparator: '.'
301
311
  })} ${pagination?.locale?.items || paginationLocal?.items || ''}`
302
- }, pagination, {
312
+ }, paginationProps, {
303
313
  onChange: (page, pageSize1) => {
304
314
  if (pagination.onChange) {
305
315
  pagination.onChange(page, pageSize1);
@@ -76,6 +76,8 @@ export type Locale = {
76
76
  export type PaginationConfig = Omit<TablePaginationConfig, 'locale' | 'current'> & {
77
77
  currentPage?: number;
78
78
  locale?: PagingLocale;
79
+ /** Chế độ phân trang. Mặc định là client để giữ tương thích với hành vi hiện tại. */
80
+ mode?: 'client' | 'server';
79
81
  };
80
82
  export type AnyObject = Record<PropertyKey, any>;
81
83
  export type IFormat = {
@@ -68,7 +68,6 @@ var _moment = _interopRequireDefault(require("moment"));
68
68
  const newGuid = () => {
69
69
  for (let i = 0; i < 20; i++) {
70
70
  // @ts-ignore
71
- // const id = crypto.randomUUID()
72
71
  return (0, _uuid.v4)();
73
72
  }
74
73
  };
@@ -86,7 +86,6 @@ var _hooks = require("../../grid-component/hooks");
86
86
  const newGuid = () => {
87
87
  for (let i = 0; i < 20; i++) {
88
88
  // @ts-ignore
89
- // const id = crypto.randomUUID()
90
89
  return (0, _uuid.v4)();
91
90
  }
92
91
  };
@@ -99,6 +99,8 @@ const InternalTable = props => {
99
99
  pageIndex: pagination && pagination.currentPage ? pagination.currentPage - 1 : 0,
100
100
  pageSize: pagination && pagination.pageSize ? pagination.pageSize : 20
101
101
  });
102
+ const isServerPagination = Boolean(pagination && pagination.mode === 'server');
103
+ const shouldUseClientPagination = Boolean(pagination) && !infiniteScroll && !isServerPagination;
102
104
  const [columnSizing, setColumnSizing] = _react.default.useState({});
103
105
  const [columnSizingInfo, setColumnSizingInfo] = _react.default.useState({});
104
106
 
@@ -274,7 +276,10 @@ const InternalTable = props => {
274
276
  getGroupedRowModel: (0, _reactTable.getGroupedRowModel)(),
275
277
  // onExpandedChange: setExpanded,
276
278
  getExpandedRowModel: (0, _reactTable.getExpandedRowModel)(),
277
- getPaginationRowModel: pagination && !infiniteScroll ? (0, _reactTable.getPaginationRowModel)() : undefined,
279
+ manualPagination: isServerPagination,
280
+ // Chỉ để TanStack tự phân trang khi có pagination, không dùng infinite scroll và đang ở chế độ client.
281
+ // Với server pagination, dữ liệu đã được BE phân trang nên không chạy getPaginationRowModel() để tránh phân trang lần 2.
282
+ getPaginationRowModel: shouldUseClientPagination ? (0, _reactTable.getPaginationRowModel)() : undefined,
278
283
  onPaginationChange: setPagination,
279
284
  onColumnVisibilityChange: setColumnVisibility
280
285
  // onColumnPinningChange,
@@ -87,6 +87,16 @@ const TableContainer = props => {
87
87
  } = props;
88
88
  const [paginationLocal] = (0, _locale.useLocale)('Pagination');
89
89
  const [tableLocal] = (0, _locale.useLocale)('Table');
90
+ const paginationProps = _react.default.useMemo(() => {
91
+ if (!pagination) {
92
+ return undefined;
93
+ }
94
+ const paginationConfig = {
95
+ ...pagination
96
+ };
97
+ delete paginationConfig.mode;
98
+ return paginationConfig;
99
+ }, [pagination]);
90
100
  const tableContainerRef = _react.default.useRef(null);
91
101
  const containerRef = _react.default.useRef(null);
92
102
  const bottomToolbarRef = _react.default.useRef(null);
@@ -218,7 +228,7 @@ const TableContainer = props => {
218
228
  showTotal: (totalItems, range) =>
219
229
  // @ts-ignore
220
230
  `${range[0]}-${range[1]} / ${totalItems} ${t ? t(pagination?.locale?.items ?? 'items') : 'items'}`
221
- }, pagination)), typeof actionTemplate === 'function' ? actionTemplate() : actionTemplate, toolbarItemTopRight && /*#__PURE__*/_react.default.createElement("div", {
231
+ }, paginationProps)), typeof actionTemplate === 'function' ? actionTemplate() : actionTemplate, toolbarItemTopRight && /*#__PURE__*/_react.default.createElement("div", {
222
232
  style: {
223
233
  flex: 1,
224
234
  overflow: 'hidden'
@@ -307,7 +317,7 @@ const TableContainer = props => {
307
317
  })} / ${(0, _reactNumericComponent.numericFormatter)((totalItems ?? 0).toString(), {
308
318
  thousandSeparator: '.'
309
319
  })} ${pagination?.locale?.items || paginationLocal?.items || ''}`
310
- }, pagination, {
320
+ }, paginationProps, {
311
321
  onChange: (page, pageSize1) => {
312
322
  if (pagination.onChange) {
313
323
  pagination.onChange(page, pageSize1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-grid-template",
3
- "version": "1.9.82",
3
+ "version": "1.9.83",
4
4
  "description": "es-grid-template",
5
5
  "keywords": [
6
6
  "react",