trithuc-mvc-react 3.2.3 → 3.2.4

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.
@@ -288,6 +288,15 @@ const DataTable = ({ multipleActions = [], page, setPage = () => {}, disableEdit
288
288
 
289
289
  return (
290
290
  <>
291
+ <Grid container>
292
+ {!hasTabpanel && (
293
+ <Grid alignSelf={"center"} sx={{ pl: 2 }}>
294
+ <Typography variant="body1">
295
+ Tổng số lượng: <span>{total}</span>
296
+ </Typography>
297
+ </Grid>
298
+ )}
299
+ </Grid>
291
300
  <TableContainer sx={{ position: "relative" }}>
292
301
  <TableToolbar
293
302
  onSelectAllClick={handleSelectAllClick}
@@ -342,14 +351,6 @@ const DataTable = ({ multipleActions = [], page, setPage = () => {}, disableEdit
342
351
  </TableContainer>
343
352
 
344
353
  <Grid container>
345
- {!hasTabpanel && (
346
- <Grid alignSelf={"center"} sx={{ pl: 2 }}>
347
- <Typography variant="body1">
348
- Tổng số lượng: <span>{total}</span>
349
- </Typography>
350
- </Grid>
351
- )}
352
-
353
354
  <Grid size={12}>
354
355
  <TablePaginationCustom
355
356
  count={total}
@@ -298,6 +298,15 @@ const DataTableSM = ({ multipleActions = [], page, setPage = () => {}, disableEd
298
298
 
299
299
  return (
300
300
  <>
301
+ <Grid container>
302
+ {!hasTabpanel && (
303
+ <Grid alignSelf={"center"} sx={{ pl: 2 }}>
304
+ <Typography variant="body1">
305
+ Tổng số lượng: <span>{total}</span>
306
+ </Typography>
307
+ </Grid>
308
+ )}
309
+ </Grid>
301
310
  <TableContainer sx={{ position: "relative" }}>
302
311
  <TableToolbar
303
312
  onSelectAllClick={handleSelectAllClick}
@@ -352,14 +361,6 @@ const DataTableSM = ({ multipleActions = [], page, setPage = () => {}, disableEd
352
361
  </TableContainer>
353
362
 
354
363
  <Grid container>
355
- {!hasTabpanel && (
356
- <Grid alignSelf={"center"} sx={{ pl: 2 }}>
357
- <Typography variant="body1" sx={{ fontSize: "0.7rem" }}>
358
- Tổng số lượng: <span>{total}</span>
359
- </Typography>
360
- </Grid>
361
- )}
362
-
363
364
  <Grid size={12}>
364
365
  <TablePaginationCustom
365
366
  count={total}
@@ -14,6 +14,7 @@ export function FilterElement({
14
14
  keyLabel,
15
15
  childrenFields,
16
16
  datas,
17
+ multiple = false,
17
18
  loading = false,
18
19
  onChange = () => {},
19
20
  size = "small",
@@ -74,35 +75,83 @@ export function FilterElement({
74
75
  );
75
76
 
76
77
  case "autocomplete": {
77
- //Bùa bởi vì không hiện giá trị đầu tiên
78
- let autocompleteValue = datas?.find((item) => item[keyValue] == dataSearch[name]);
79
- autocompleteValue = autocompleteValue ? { ...autocompleteValue } : { [keyLabel]: "" };
80
- return (
81
- <Autocomplete
82
- key={name}
83
- name={name}
84
- disablePortal
85
- loading={loading}
86
- noOptionsText="Không có dữ liệu"
87
- fullWidth
88
- options={datas ?? []}
89
- onChange={(event, newValue) => {
90
- let updateObject = { [name]: newValue?.[keyValue] };
91
- onFieldChange(newValue?.[keyValue]);
92
- onChange(newValue);
93
- setPage(0);
94
- childrenFields?.forEach((childrenField) => {
95
- setValue(childrenField, null, { shouldTouch: true });
96
- updateObject[childrenField] = null;
97
- });
78
+ if (multiple) {
79
+ const autocompleteValue = multiple
80
+ ? datas.filter((item) => (value || []).includes(item[keyValue]))
81
+ : datas.find((item) => item[keyValue] === value) ?? null;
98
82
 
99
- setDataSearch({ ...dataSearch, ...updateObject });
100
- }}
101
- value={autocompleteValue}
102
- getOptionLabel={(option) => option?.[keyLabel]}
103
- renderInput={(params) => <TextField {...params} label={label} placeholder={placeholder} />}
104
- />
105
- );
83
+ const parsedValue = multiple ? autocompleteValue : autocompleteValue;
84
+
85
+ return (
86
+ <Autocomplete
87
+ key={name}
88
+ name={name}
89
+ disablePortal
90
+ multiple={multiple}
91
+ loading={loading}
92
+ noOptionsText="Không có dữ liệu"
93
+ fullWidth
94
+ options={datas}
95
+ value={parsedValue}
96
+ onChange={(event, newValue) => {
97
+ // ✅ Khai báo biến trước khi sử dụng
98
+ const updateObject = {
99
+ [name]: multiple ? JSON.stringify(newValue.map((item) => item[keyValue])) : newValue?.[keyValue]
100
+ };
101
+
102
+ if (multiple) {
103
+ onFieldChange(newValue.map((item) => item[keyValue]));
104
+ } else {
105
+ onFieldChange(newValue?.[keyValue]);
106
+ }
107
+
108
+ onChange(newValue);
109
+ setPage(0);
110
+
111
+ // ✅ Xử lý các trường con (nếu có)
112
+ childrenFields?.forEach((childrenField) => {
113
+ setValue(childrenField, null, { shouldTouch: true });
114
+ updateObject[childrenField] = null;
115
+ });
116
+
117
+ // ✅ Cập nhật state tìm kiếm
118
+ setDataSearch({ ...dataSearch, ...updateObject });
119
+ }}
120
+ getOptionLabel={(option) => option?.[keyLabel] || ""}
121
+ renderInput={(params) => <TextField {...params} label={label} placeholder={placeholder} />}
122
+ />
123
+ );
124
+ } else {
125
+ //Bùa bởi vì không hiện giá trị đầu tiên
126
+ let autocompleteValue = datas?.find((item) => item[keyValue] == dataSearch[name]);
127
+ autocompleteValue = autocompleteValue ? { ...autocompleteValue } : { [keyLabel]: "" };
128
+ return (
129
+ <Autocomplete
130
+ key={name}
131
+ name={name}
132
+ disablePortal
133
+ loading={loading}
134
+ noOptionsText="Không có dữ liệu"
135
+ fullWidth
136
+ options={datas ?? []}
137
+ onChange={(event, newValue) => {
138
+ let updateObject = { [name]: newValue?.[keyValue] };
139
+ onFieldChange(newValue?.[keyValue]);
140
+ onChange(newValue);
141
+ setPage(0);
142
+ childrenFields?.forEach((childrenField) => {
143
+ setValue(childrenField, null, { shouldTouch: true });
144
+ updateObject[childrenField] = null;
145
+ });
146
+
147
+ setDataSearch({ ...dataSearch, ...updateObject });
148
+ }}
149
+ value={autocompleteValue}
150
+ getOptionLabel={(option) => option?.[keyLabel]}
151
+ renderInput={(params) => <TextField {...params} label={label} placeholder={placeholder} />}
152
+ />
153
+ );
154
+ }
106
155
  }
107
156
  case "select":
108
157
  return (
@@ -459,7 +459,6 @@ function DataManagement({
459
459
  {viewMode === "bieudo" && bieuDo}
460
460
  </Card>
461
461
  </FormProvider>
462
-
463
462
  {/* nôi dung form */}
464
463
  {disableEditor || (
465
464
  <EditorDialog
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trithuc-mvc-react",
3
- "version": "3.2.3",
3
+ "version": "3.2.4",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"