@megha-ui/react 1.2.199 → 1.2.200
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/components/grid/index.js +37 -20
- package/dist/components/grid/types/grid.d.ts +2 -0
- package/dist/components/grid/utils/SummariseDetails.js +14 -0
- package/dist/components/grid/utils/groupedGridDetails.js +17 -5
- package/dist/components/grid/utils/groupedRow.js +17 -5
- package/package.json +1 -1
|
@@ -22,7 +22,7 @@ import Button from "../button";
|
|
|
22
22
|
import { TbAntennaBarsOff, TbCalculator, TbCalculatorFilled, TbCalculatorOff, } from "react-icons/tb";
|
|
23
23
|
import { TbCopy, TbCopyOff } from "react-icons/tb";
|
|
24
24
|
import { formatValue } from "../../services/commonService";
|
|
25
|
-
const Grid = ({ columns, wrapperClass, updateGridColumns, data, height, sortable = true, paginate, rowsPerPageOptions = [10, 20, 50, 100], defaultRowsPerPage = 100, widthMode = "custom", bulkSelect = false, cellBorder = false, rowHeight = 38, onRowClick, rowCount = false, rowBorder = true, showMenu = false, search = false, defaultSearchOperation = "contains", gridBorder = false, isLoading = false, rowTopBorder, rowBottomBorder, rowLeftBorder, rowRightBorder, headerBackground = "var(--row-header-bg)", headerTopBorder = "none", headerBottomBorder = "none", SettingIcon, ExportIcon, ignoredExportItems = ["action", "actions"], borderColor = "#dbdfe9", updateColumns, showHideAvailable = false, columnSearchOutside = false, multiSorting = false, exportAvailable = false, exportableFileName = "", groupBy, updateGroupBy, rowKey = "id", hlBorderColor = "black", selectedRow, selectedRowStyle = {
|
|
25
|
+
const Grid = ({ columns, wrapperClass, updateGridColumns, data, height, sortable = true, paginate, rowsPerPageOptions = [10, 20, 50, 100], defaultRowsPerPage = 100, widthMode = "custom", bulkSelect = false, cellBorder = false, rowHeight = 38, onRowClick, rowCount = false, rowBorder = true, showMenu = false, search = false, defaultSearchOperation = "contains", gridBorder = false, isLoading = false, rowTopBorder, rowBottomBorder, rowLeftBorder, rowRightBorder, headerBackground = "var(--row-header-bg)", headerTopBorder = "none", headerBottomBorder = "none", SettingIcon, ExportIcon, ignoredExportItems = ["action", "actions"], borderColor = "#dbdfe9", updateColumns, showHideAvailable = false, columnSearchOutside = false, multiSorting = false, exportAvailable = false, exportableFileName = "", groupBy, groupLevels, updateGroupBy, rowKey = "id", hlBorderColor = "black", selectedRow, selectedRowStyle = {
|
|
26
26
|
borderLeft: "0.5rem solid #d9d9d9",
|
|
27
27
|
}, defaultSort, noKeyEvents = true, customOperation, hasCustomOperation, globalSearch, headerDropdownIndex, draggable = false, resizable = false, updateGridData, widthUnits, checkboxWrapper, ignoreHugContent = false, setRendered, isSummarise = true, fullScreenAvailable = true, defaultGroupOpen, alternateRowColor = true, activeCalculateColor = "#2377BA", calculatetextColor = "#fff", actionsKey = "actions", saveAsNewView = false, handleSaveAsView, saveAsViewIcon, filterData, chipColor = "#ccc", withAscii = false, propSummariseKeys, SummariseIcon, summarizeColor = "black", isExpandable = false, expandedRow, extraRow, selectedCheckBox, setSelectedCheckbox, ignoreRowSelect, setOpenedRows, openedRows, getLoadingState, globalSearchOpen = false, updateFixedFilterValues = (fixedFilterValues) => {
|
|
28
28
|
console.log("Update fixed filter values not implemented", fixedFilterValues);
|
|
@@ -542,40 +542,56 @@ const Grid = ({ columns, wrapperClass, updateGridColumns, data, height, sortable
|
|
|
542
542
|
}
|
|
543
543
|
return column;
|
|
544
544
|
}));
|
|
545
|
-
if
|
|
545
|
+
// Prefer explicit composite groupLevels if provided; fallback to string groupBy
|
|
546
|
+
if (groupLevels && groupLevels.length > 0) {
|
|
547
|
+
const gb = groupLevels
|
|
548
|
+
.map((level) => level.filter(Boolean).join("+"))
|
|
549
|
+
.filter(Boolean)
|
|
550
|
+
.join(",");
|
|
551
|
+
setGridGroupBy(gb);
|
|
552
|
+
}
|
|
553
|
+
else if (groupBy) {
|
|
546
554
|
setGridGroupBy(groupBy);
|
|
547
555
|
}
|
|
548
|
-
}, [gridColumns, groupBy]);
|
|
549
|
-
const
|
|
550
|
-
|
|
551
|
-
|
|
556
|
+
}, [gridColumns, groupBy, groupLevels]);
|
|
557
|
+
const parseGroupLevels = (gb) => gb
|
|
558
|
+
.split(",")
|
|
559
|
+
.filter((lvl) => lvl)
|
|
560
|
+
.map((lvl) => lvl.split("+").filter((k) => k));
|
|
561
|
+
const groupByCompositeLevels = (data, groupLevelsArr) => {
|
|
562
|
+
const groupData = (items, levels, level = 0) => {
|
|
563
|
+
if (level >= levels.length)
|
|
552
564
|
return items;
|
|
553
565
|
const groupedResult = [];
|
|
554
|
-
const
|
|
566
|
+
const levelKeys = levels[level];
|
|
567
|
+
const map = new Map();
|
|
555
568
|
items.forEach((item) => {
|
|
556
|
-
var _a;
|
|
557
|
-
const
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
569
|
+
const parts = levelKeys.map((k) => { var _a, _b; return ((_b = (_a = item[k]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : "").toString(); });
|
|
570
|
+
const keyName = levelKeys.join("+");
|
|
571
|
+
const display = parts.join(" | ");
|
|
572
|
+
const compositeKey = parts.join("\u0001");
|
|
573
|
+
const existing = map.get(compositeKey);
|
|
574
|
+
if (existing) {
|
|
575
|
+
existing.values.push(item);
|
|
561
576
|
}
|
|
562
577
|
else {
|
|
563
|
-
|
|
564
|
-
key:
|
|
565
|
-
value:
|
|
578
|
+
map.set(compositeKey, {
|
|
579
|
+
key: keyName,
|
|
580
|
+
value: display,
|
|
566
581
|
count: 0,
|
|
567
582
|
subGroups: [],
|
|
568
583
|
values: [item],
|
|
569
584
|
});
|
|
570
585
|
}
|
|
571
586
|
});
|
|
572
|
-
|
|
587
|
+
const result = Array.from(map.values());
|
|
588
|
+
result.forEach((group) => {
|
|
573
589
|
group.count = group.values.length;
|
|
574
|
-
group.subGroups = groupData(group.values,
|
|
590
|
+
group.subGroups = groupData(group.values, levels, level + 1);
|
|
575
591
|
});
|
|
576
|
-
return
|
|
592
|
+
return result;
|
|
577
593
|
};
|
|
578
|
-
return groupData(data,
|
|
594
|
+
return groupData(data, groupLevelsArr);
|
|
579
595
|
};
|
|
580
596
|
const flattenGroupedData = (groupedData, level, groupedValues = [], parentKeys = []) => {
|
|
581
597
|
const flatArray = [];
|
|
@@ -615,7 +631,8 @@ const Grid = ({ columns, wrapperClass, updateGridColumns, data, height, sortable
|
|
|
615
631
|
};
|
|
616
632
|
useEffect(() => {
|
|
617
633
|
if (gridGroupBy && gridGroupBy !== "") {
|
|
618
|
-
const
|
|
634
|
+
const levels = parseGroupLevels(gridGroupBy);
|
|
635
|
+
const groupedArray = groupByCompositeLevels(sortedData, levels);
|
|
619
636
|
const flatGroupedArray = flattenGroupedData(groupedArray, 1);
|
|
620
637
|
setGroupedData(flatGroupedArray);
|
|
621
638
|
const grouped = flatGroupedArray
|
|
@@ -104,6 +104,8 @@ export interface OjasGridProps {
|
|
|
104
104
|
exportableFileName?: string;
|
|
105
105
|
groupBy?: string;
|
|
106
106
|
updateGroupBy?: (value: string) => void;
|
|
107
|
+
/** Optional composite grouping levels; each inner array is a same-level composite group */
|
|
108
|
+
groupLevels?: string[][];
|
|
107
109
|
hlBorderColor?: string;
|
|
108
110
|
selectedRow?: number;
|
|
109
111
|
selectedRowStyle?: React.CSSProperties;
|
|
@@ -130,6 +130,20 @@ const SummariseDetails = ({ columns, rowIndex, groupBy, sortable, cellStyle, col
|
|
|
130
130
|
.filter((item) => item && !removedKeys.includes(item))
|
|
131
131
|
.map((_groupBy) => {
|
|
132
132
|
var _a;
|
|
133
|
+
if (_groupBy.includes("+")) {
|
|
134
|
+
const width = (() => {
|
|
135
|
+
const keys = _groupBy.split("+");
|
|
136
|
+
const sum = keys.reduce((acc, k) => {
|
|
137
|
+
const col = columns.find((c) => c.key === k);
|
|
138
|
+
const w = (col === null || col === void 0 ? void 0 : col.width)
|
|
139
|
+
? parseFloat(col.width.toString())
|
|
140
|
+
: parseFloat((columnWidths[`column-${k}`] || "0").toString());
|
|
141
|
+
return acc + (isNaN(w) ? 0 : w);
|
|
142
|
+
}, 0);
|
|
143
|
+
return `${sum}px`;
|
|
144
|
+
})();
|
|
145
|
+
return (_jsx("div", { style: Object.assign(Object.assign({}, cellStyle), { position: "relative", width: widthMode === "auto" ? "auto" : width, padding: _groupBy ? "0.5rem" : 0 }), className: `column composite-${_groupBy}`, children: "--" }, `${groupedData}-${_groupBy}`));
|
|
146
|
+
}
|
|
133
147
|
const column = columns.find((column) => column.key === _groupBy);
|
|
134
148
|
const columnKey = groupedData
|
|
135
149
|
? `${groupedData}-${column === null || column === void 0 ? void 0 : column.key}`
|
|
@@ -78,11 +78,23 @@ const GroupedGrid = ({ groupedData, rowOpened, startIndex, endIndex, alternateRo
|
|
|
78
78
|
fontSize: "inherit",
|
|
79
79
|
width: widthMode === "auto"
|
|
80
80
|
? "auto"
|
|
81
|
-
:
|
|
82
|
-
?
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
81
|
+
: item.key.includes("+")
|
|
82
|
+
? (() => {
|
|
83
|
+
const keys = item.key.split("+");
|
|
84
|
+
const sum = keys.reduce((acc, k) => {
|
|
85
|
+
const col = gridColumns.find((c) => c.key === k);
|
|
86
|
+
const w = (col === null || col === void 0 ? void 0 : col.width)
|
|
87
|
+
? parseFloat(col.width.toString())
|
|
88
|
+
: parseFloat((columnWidths[`column-${k}`] || "0").toString());
|
|
89
|
+
return acc + (isNaN(w) ? 0 : w);
|
|
90
|
+
}, 0);
|
|
91
|
+
return `calc(${sum}px + 25px)`;
|
|
92
|
+
})()
|
|
93
|
+
: ((_b = gridColumns.find((column) => column.key === item.key)) === null || _b === void 0 ? void 0 : _b.width)
|
|
94
|
+
? `calc(${(_c = gridColumns.find((column) => column.key === item.key)) === null || _c === void 0 ? void 0 : _c.width} + 25px)`
|
|
95
|
+
: columnWidths[`column-${item.key}`]
|
|
96
|
+
? `calc(${columnWidths[`column-${item.key}`]} + 25px)`
|
|
97
|
+
: "fit-content",
|
|
86
98
|
background: "inherit",
|
|
87
99
|
flexShrink: 0,
|
|
88
100
|
flexGrow: 0,
|
|
@@ -35,11 +35,23 @@ const GroupedRow = ({ item, rowStyle, cellStyle, rowHeight, columns, widthMode,
|
|
|
35
35
|
return (_jsx("div", { style: {
|
|
36
36
|
width: widthMode === "auto"
|
|
37
37
|
? "auto"
|
|
38
|
-
:
|
|
39
|
-
?
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
: _groupBy.includes("+")
|
|
39
|
+
? (() => {
|
|
40
|
+
const keys = _groupBy.split("+");
|
|
41
|
+
const sum = keys.reduce((acc, k) => {
|
|
42
|
+
const col = columns.find((c) => c.key === k);
|
|
43
|
+
const w = (col === null || col === void 0 ? void 0 : col.width)
|
|
44
|
+
? parseFloat(col.width.toString())
|
|
45
|
+
: parseFloat(((hugColumnWidths === null || hugColumnWidths === void 0 ? void 0 : hugColumnWidths[`column-${k}`]) || "0").toString());
|
|
46
|
+
return acc + (isNaN(w) ? 0 : w);
|
|
47
|
+
}, 0);
|
|
48
|
+
return `calc(${sum}px + 25px)`;
|
|
49
|
+
})()
|
|
50
|
+
: ((_a = columns.find((column) => column.key === _groupBy)) === null || _a === void 0 ? void 0 : _a.width)
|
|
51
|
+
? `calc(${(_b = columns.find((column) => column.key === _groupBy)) === null || _b === void 0 ? void 0 : _b.width} + 25px)`
|
|
52
|
+
: (hugColumnWidths === null || hugColumnWidths === void 0 ? void 0 : hugColumnWidths[`column-${_groupBy}`])
|
|
53
|
+
? `calc(${hugColumnWidths === null || hugColumnWidths === void 0 ? void 0 : hugColumnWidths[`column-${_groupBy}`]} + 25px)`
|
|
54
|
+
: "fit-content",
|
|
43
55
|
padding: _groupBy ? "0.5rem" : 0,
|
|
44
56
|
backgroundColor: alternateRowColor && (index + 1) % 2 === 0
|
|
45
57
|
? "var(--row-bg)"
|
package/package.json
CHANGED