trithuc-mvc-react 3.0.1 → 3.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.
@@ -14,6 +14,14 @@ import { usePermission } from "../../hooks";
14
14
  import { TableRowRender } from "./TableRowRender";
15
15
  import TableToolbar from "./TableToolbar";
16
16
  import { useDataTable } from "./hooks";
17
+ const defaultQueryOptions = {
18
+ keepPreviousData: true, // Giữ dữ liệu cũ trong khi tải dữ liệu mới
19
+ staleTime: 1000 * 60 * 1, // Thời gian dữ liệu có thể sử dụng lại trước khi gọi lại API
20
+ cacheTime: 1000 * 60 * 30, // Thời gian dữ liệu được lưu trong cache trước khi bị xóa
21
+ refetchOnWindowFocus: true, // Tự động lấy lại dữ liệu khi người dùng quay lại tab
22
+ refetchInterval: 1000 * 30, // Mỗi 30 giây
23
+ keepPreviousData: true
24
+ };
17
25
  const DataTable = ({ multipleActions = [], page, setPage = () => {}, disableEdit, disableDelete }) => {
18
26
  const {
19
27
  tableName,
@@ -44,6 +52,7 @@ const DataTable = ({ multipleActions = [], page, setPage = () => {}, disableEdit
44
52
  pageSize: rowsPerPage,
45
53
  data: dataSearch
46
54
  }),
55
+ defaultQueryOptions,
47
56
  // keepPreviousData: true,
48
57
  onSuccess: ({ PermissionModel, status }) => {
49
58
  if (dataSearch?.TrangThaiXuLy !== undefined) {
@@ -52,6 +61,11 @@ const DataTable = ({ multipleActions = [], page, setPage = () => {}, disableEdit
52
61
  if (status) {
53
62
  setPermission(PermissionModel);
54
63
  // console.log("LOAD LAI PermissionModel");
64
+ // Cuộn lên đầu trang khi tải dữ liệu thành công
65
+ window.scrollTo({
66
+ top: 0, // Vị trí pixel muốn cuộn tới
67
+ behavior: "smooth" // Tùy chọn cuộn mượt
68
+ });
55
69
  }
56
70
  }
57
71
  });
@@ -13,6 +13,14 @@ import { usePermission } from "../../hooks";
13
13
  import { TableRowRenderSM } from "./TableRowRenderSM";
14
14
  import TableToolbar from "./TableToolbar";
15
15
  import { useDataTable } from "./hooks";
16
+ const defaultQueryOptions = {
17
+ keepPreviousData: true, // Giữ dữ liệu cũ trong khi tải dữ liệu mới
18
+ staleTime: 1000 * 60 * 1, // Thời gian dữ liệu có thể sử dụng lại trước khi gọi lại API
19
+ cacheTime: 1000 * 60 * 30, // Thời gian dữ liệu được lưu trong cache trước khi bị xóa
20
+ refetchOnWindowFocus: true, // Tự động lấy lại dữ liệu khi người dùng quay lại tab
21
+ refetchInterval: 1000 * 30, // Mỗi 30 giây
22
+ keepPreviousData: true
23
+ };
16
24
  const DataTableSM = ({ multipleActions = [], page, setPage = () => {}, disableEdit, disableDelete }) => {
17
25
  const {
18
26
  tableName,
@@ -43,6 +51,7 @@ const DataTableSM = ({ multipleActions = [], page, setPage = () => {}, disableEd
43
51
  pageSize: rowsPerPage,
44
52
  data: dataSearch
45
53
  }),
54
+ defaultQueryOptions,
46
55
  // keepPreviousData: true,
47
56
  onSuccess: ({ PermissionModel, status }) => {
48
57
  if (dataSearch?.TrangThaiXuLy !== undefined) {
@@ -51,6 +60,11 @@ const DataTableSM = ({ multipleActions = [], page, setPage = () => {}, disableEd
51
60
  if (status) {
52
61
  setPermission(PermissionModel);
53
62
  // console.log("LOAD LAI PermissionModel");
63
+ // Cuộn lên đầu trang khi tải dữ liệu thành công
64
+ window.scrollTo({
65
+ top: 0, // Vị trí pixel muốn cuộn tới
66
+ behavior: "smooth" // Tùy chọn cuộn mượt
67
+ });
54
68
  }
55
69
  }
56
70
  });
@@ -68,23 +68,35 @@ export const TableRowRender = ({
68
68
  ({
69
69
  field,
70
70
  type = "text",
71
- valueGetter = (row) => {
72
- return row[field];
73
- },
71
+ valueGetter = (row) => row[field], // Giá trị mặc định
74
72
  renderCell,
75
73
  valueFormat = (e) => e
76
74
  }) => {
77
- let align = type == "image" || type == "number" || type == "date" || type == "datetime" ? "right" : "left";
78
- if (type == "textCenter") align = "center";
75
+ // Xác định `align`
76
+ const alignMap = {
77
+ image: "right",
78
+ number: "right",
79
+ date: "right",
80
+ datetime: "right",
81
+ textCenter: "center",
82
+ textLeft: "left",
83
+ textRight: "right"
84
+ };
85
+ const align = alignMap[type] || "left"; // Mặc định là "left"
86
+
79
87
  return (
80
- <TableCell key={`${row[selectedField]}-${field}`} align={align}>
88
+ <TableCell
89
+ key={`${row[selectedField] || "unknown"}-${field}`} // Thêm fallback cho `key`
90
+ align={align}
91
+ >
81
92
  {renderCell ? renderCell(row) : valueFormat(valueGetter(row))}
82
93
  </TableCell>
83
94
  );
84
95
  }
85
96
  )}
97
+
86
98
  {!disableStatus && canEdit && (
87
- <TableCell>
99
+ <TableCell align="center">
88
100
  <Switch
89
101
  checked={row[statusKey]}
90
102
  onChange={() => {
@@ -13,7 +13,7 @@ function TablePaginationCustom({ count, rowsPerPage, page, onPageChange, onRowsP
13
13
  <Box sx={{ overflowX: "auto", width: "100%" }}>
14
14
  <TablePagination
15
15
  {...rest}
16
- rowsPerPageOptions={[5, 10, 25, 100]}
16
+ rowsPerPageOptions={[5, 10, 20, 25, 50, 100]}
17
17
  component="div"
18
18
  count={count}
19
19
  rowsPerPage={rowsPerPage}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trithuc-mvc-react",
3
- "version": "3.0.1",
3
+ "version": "3.0.3",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"