added expanding row feature

This commit is contained in:
pramod.mahajan 2025-12-27 11:09:38 +05:30
parent 3ab70dc86f
commit 526929d298

View File

@ -62,17 +62,20 @@ export function useGridCore({
const q = search.toLowerCase();
filtered = filtered.filter((r) =>
Object.values(r).some((v) =>
String(v ?? "").toLowerCase().includes(q)
String(v ?? "")
.toLowerCase()
.includes(q)
)
);
}
if (sortBy.key) {
const dir = sortBy.dir === "asc" ? 1 : -1;
filtered = [...filtered].sort((a, b) =>
String(a[sortBy.key] ?? "").localeCompare(
String(b[sortBy.key] ?? "")
) * dir
filtered = [...filtered].sort(
(a, b) =>
String(a[sortBy.key] ?? "").localeCompare(
String(b[sortBy.key] ?? "")
) * dir
);
}
@ -122,6 +125,15 @@ export function useGridCore({
);
}, []);
// *---------------- ROW EXPAND -----------------------*/
const toggleExpand = useCallback((id) => {
setExpanded((prev) => {
const s = new Set(prev);
s.has(id) ? s.delete(id) : s.add(id);
return s;
});
}, []);
return {
/* paging */
page,
@ -159,7 +171,7 @@ export function useGridCore({
visibleColumns,
updateColumn,
setColState,
toggleExpand,
/* data */
rows,
setRows,
@ -170,7 +182,6 @@ export function useGridCore({
};
}
export function useDropdownPosition(btnRef, menuRef, isOpen, level = 0) {
const [style, setStyle] = useState({});