trithuc-mvc-react 3.2.2 → 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}
@@ -9,10 +9,12 @@ export function FilterElement({
9
9
  name,
10
10
  type,
11
11
  label,
12
+ placeholder,
12
13
  keyValue,
13
14
  keyLabel,
14
15
  childrenFields,
15
16
  datas,
17
+ multiple = false,
16
18
  loading = false,
17
19
  onChange = () => {},
18
20
  size = "small",
@@ -43,6 +45,7 @@ export function FilterElement({
43
45
  return (
44
46
  <TextField
45
47
  {...rest}
48
+ label={label}
46
49
  fullWidth
47
50
  value={value ?? ""}
48
51
  onChange={(e) => {
@@ -50,7 +53,7 @@ export function FilterElement({
50
53
  handleFilterChangeDebounce(name, e.target.value);
51
54
  setPage(0);
52
55
  }}
53
- placeholder={label}
56
+ placeholder={placeholder}
54
57
  variant="outlined"
55
58
  InputProps={{
56
59
  startAdornment: (
@@ -72,35 +75,83 @@ export function FilterElement({
72
75
  );
73
76
 
74
77
  case "autocomplete": {
75
- //Bùa bởi vì không hiện giá trị đầu tiên
76
- let autocompleteValue = datas?.find((item) => item[keyValue] == dataSearch[name]);
77
- autocompleteValue = autocompleteValue ? { ...autocompleteValue } : { [keyLabel]: "" };
78
- return (
79
- <Autocomplete
80
- key={name}
81
- name={name}
82
- disablePortal
83
- loading={loading}
84
- noOptionsText="Không có dữ liệu"
85
- fullWidth
86
- options={datas ?? []}
87
- onChange={(event, newValue) => {
88
- let updateObject = { [name]: newValue?.[keyValue] };
89
- onFieldChange(newValue?.[keyValue]);
90
- onChange(newValue);
91
- setPage(0);
92
- childrenFields?.forEach((childrenField) => {
93
- setValue(childrenField, null, { shouldTouch: true });
94
- updateObject[childrenField] = null;
95
- });
78
+ if (multiple) {
79
+ const autocompleteValue = multiple
80
+ ? datas.filter((item) => (value || []).includes(item[keyValue]))
81
+ : datas.find((item) => item[keyValue] === value) ?? null;
96
82
 
97
- setDataSearch({ ...dataSearch, ...updateObject });
98
- }}
99
- value={autocompleteValue}
100
- getOptionLabel={(option) => option?.[keyLabel]}
101
- renderInput={(params) => <TextField {...params} label={label} />}
102
- />
103
- );
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
+ }
104
155
  }
105
156
  case "select":
106
157
  return (
@@ -112,6 +163,7 @@ export function FilterElement({
112
163
  fullWidth
113
164
  size={size}
114
165
  label={label}
166
+ placeholder={placeholder}
115
167
  value={value}
116
168
  displayEmpty
117
169
  onChange={(e) => {
@@ -54,7 +54,7 @@ export const FilterGod = ({ tableName, filters, filterButtons, elementSize = "sm
54
54
 
55
55
  <AccordionDetails>
56
56
  <Grid container spacing={1}>
57
- {filters.map(({ field, label, size, ...rest }) => {
57
+ {filters.map(({ field, label, placeHolder, size, ...rest }) => {
58
58
  if (rest.type === "date-range") {
59
59
  const [label1, label2] = Array.isArray(label) ? label : ["Từ ngày", "Đến ngày"];
60
60
  const handleClear = (key) => {
@@ -183,7 +183,7 @@ export const FilterGod = ({ tableName, filters, filterButtons, elementSize = "sm
183
183
  }
184
184
  return (
185
185
  <Grid key={field.toString()} size={{ ...size }}>
186
- <FilterElement name={field.toString()} {...rest} setPage={setPage} />
186
+ <FilterElement name={field.toString()} label={label} placeholder={placeHolder} {...rest} setPage={setPage} />
187
187
  </Grid>
188
188
  );
189
189
  })}
@@ -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.2",
3
+ "version": "3.2.4",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"