next-helios-fe 1.4.10 → 1.4.12
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/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/components/table/index.tsx +44 -34
package/package.json
CHANGED
@@ -83,7 +83,10 @@ export const Table: TableComponentProps = ({
|
|
83
83
|
[key: string]: any;
|
84
84
|
}[]
|
85
85
|
>([]);
|
86
|
-
const [sortBy, setSortBy] = useState<
|
86
|
+
const [sortBy, setSortBy] = useState<any>({
|
87
|
+
column: "",
|
88
|
+
order: "",
|
89
|
+
});
|
87
90
|
const [excluded, setExcluded] = useState<string[]>([]);
|
88
91
|
|
89
92
|
const height =
|
@@ -132,7 +135,7 @@ export const Table: TableComponentProps = ({
|
|
132
135
|
}, [header, data]);
|
133
136
|
|
134
137
|
const filteredData = useMemo(() => {
|
135
|
-
|
138
|
+
const tempData = data
|
136
139
|
?.filter((item) => {
|
137
140
|
if (search === "") {
|
138
141
|
return item;
|
@@ -140,8 +143,8 @@ export const Table: TableComponentProps = ({
|
|
140
143
|
header.some((headerItem) => {
|
141
144
|
return item[headerItem.key as keyof typeof item]
|
142
145
|
?.toString()
|
143
|
-
|
144
|
-
|
146
|
+
?.toLowerCase()
|
147
|
+
?.includes(search.toLowerCase());
|
145
148
|
})
|
146
149
|
) {
|
147
150
|
return item;
|
@@ -150,9 +153,9 @@ export const Table: TableComponentProps = ({
|
|
150
153
|
?.filter((item) => {
|
151
154
|
return filter.every((filterItem) => {
|
152
155
|
return item[filterItem.key as keyof typeof item]
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
+
?.toString()
|
157
|
+
?.toLowerCase()
|
158
|
+
?.includes(filterItem.value.toLowerCase());
|
156
159
|
});
|
157
160
|
})
|
158
161
|
.filter((item) => {
|
@@ -164,7 +167,27 @@ export const Table: TableComponentProps = ({
|
|
164
167
|
);
|
165
168
|
});
|
166
169
|
});
|
167
|
-
|
170
|
+
|
171
|
+
if (sortBy.column === "") {
|
172
|
+
return tempData;
|
173
|
+
} else {
|
174
|
+
return tempData?.sort((a, b): any => {
|
175
|
+
if (sortBy.column === "") {
|
176
|
+
return a.id > b.id ? 1 : -1;
|
177
|
+
} else if (sortBy.order === "asc") {
|
178
|
+
return a[sortBy.column as keyof typeof a] >
|
179
|
+
b[sortBy.column as keyof typeof b]
|
180
|
+
? 1
|
181
|
+
: -1;
|
182
|
+
} else if (sortBy.order === "desc") {
|
183
|
+
return a[sortBy.column as keyof typeof a] <
|
184
|
+
b[sortBy.column as keyof typeof b]
|
185
|
+
? 1
|
186
|
+
: -1;
|
187
|
+
}
|
188
|
+
});
|
189
|
+
}
|
190
|
+
}, [header, data, filter, categoryFilter, search, sortBy]);
|
168
191
|
|
169
192
|
const headerArr = header
|
170
193
|
?.filter((item) => !excluded.includes(item.key))
|
@@ -180,18 +203,18 @@ export const Table: TableComponentProps = ({
|
|
180
203
|
type="button"
|
181
204
|
className="group/header flex justify-between items-center gap-4 w-full"
|
182
205
|
onClick={() => {
|
183
|
-
setSortBy(
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
206
|
+
setSortBy((prev: any) => {
|
207
|
+
if (prev.column !== item.key) {
|
208
|
+
return { column: item.key, order: "asc" };
|
209
|
+
} else if (
|
210
|
+
prev.column === item.key &&
|
211
|
+
prev.order === "asc"
|
212
|
+
) {
|
213
|
+
return { column: item.key, order: "desc" };
|
214
|
+
} else {
|
215
|
+
return { column: "", order: "" };
|
216
|
+
}
|
217
|
+
});
|
195
218
|
}}
|
196
219
|
>
|
197
220
|
{item.title}
|
@@ -309,19 +332,6 @@ export const Table: TableComponentProps = ({
|
|
309
332
|
});
|
310
333
|
|
311
334
|
const dataArr = filteredData
|
312
|
-
?.sort((a, b) => {
|
313
|
-
if (sortBy[1] === "asc") {
|
314
|
-
return a[sortBy[0] as keyof typeof a] > b[sortBy[0] as keyof typeof b]
|
315
|
-
? 1
|
316
|
-
: -1;
|
317
|
-
} else if (sortBy[1] === "desc") {
|
318
|
-
return a[sortBy[0] as keyof typeof a] < b[sortBy[0] as keyof typeof b]
|
319
|
-
? 1
|
320
|
-
: -1;
|
321
|
-
} else {
|
322
|
-
return a.id > b.id ? 1 : -1;
|
323
|
-
}
|
324
|
-
})
|
325
335
|
?.slice((page - 1) * maxRow, page * maxRow)
|
326
336
|
?.map((item, index) => {
|
327
337
|
return (
|
@@ -578,7 +588,7 @@ export const Table: TableComponentProps = ({
|
|
578
588
|
{ label: "50", value: "50" },
|
579
589
|
{ label: "100", value: "100" },
|
580
590
|
]}
|
581
|
-
value={maxRow
|
591
|
+
value={maxRow?.toString()}
|
582
592
|
onChange={(e) => {
|
583
593
|
setMaxRow(Number(e.target.value));
|
584
594
|
}}
|