@megha-ui/react 1.2.237 → 1.2.239
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.
|
@@ -230,7 +230,11 @@ const Dropdown = ({ options, selectedValues, onChange, placeholder = "Select..."
|
|
|
230
230
|
const handleClear = () => {
|
|
231
231
|
if (!isClear)
|
|
232
232
|
return;
|
|
233
|
-
onApplyChange
|
|
233
|
+
onApplyChange
|
|
234
|
+
? onApplyChange([])
|
|
235
|
+
: onSelectChange
|
|
236
|
+
? onSelectChange([])
|
|
237
|
+
: onChange([]);
|
|
234
238
|
};
|
|
235
239
|
useEffect(() => {
|
|
236
240
|
if (!isMultiple && intermediateValues.length > 0) {
|
|
@@ -362,7 +366,7 @@ const Dropdown = ({ options, selectedValues, onChange, placeholder = "Select..."
|
|
|
362
366
|
width: "100%",
|
|
363
367
|
}, children: _jsxs("span", { style: { marginLeft: "0.5rem" }, children: ["+ Create ", searchTerm] }) })] }, String(searchTerm))) : groupedOptions.length > 0 ? (groupedOptions.map((groupOption, gIndex) => (_jsxs("div", { children: [_jsx("div", { style: {
|
|
364
368
|
padding: "0.25rem 0 0.25rem 1rem",
|
|
365
|
-
backgroundColor: "#dddddd"
|
|
369
|
+
backgroundColor: "#dddddd",
|
|
366
370
|
}, children: groupOption.groupedValue }), groupOption.options.map((option, index) => {
|
|
367
371
|
let prevOptions = groupedOptions.filter((item, index) => index < gIndex);
|
|
368
372
|
prevOptions = [
|
|
@@ -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, updateGroupBy, compositeGroupBy = false, 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, isHideDups = false, 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);
|
|
@@ -549,6 +549,38 @@ const Grid = ({ columns, wrapperClass, updateGridColumns, data, height, sortable
|
|
|
549
549
|
}
|
|
550
550
|
}, [gridColumns, groupBy]);
|
|
551
551
|
const groupByMultipleKeys = (data, groupByKeys) => {
|
|
552
|
+
// When compositeGroupBy is enabled and multiple keys are selected,
|
|
553
|
+
// treat the selected keys as a single composite grouping (one level)
|
|
554
|
+
if (compositeGroupBy && groupByKeys.length > 1) {
|
|
555
|
+
const groupsMap = new Map();
|
|
556
|
+
const allKeys = groupByKeys.filter((k) => k);
|
|
557
|
+
const lastKey = allKeys[allKeys.length - 1];
|
|
558
|
+
data.forEach((item) => {
|
|
559
|
+
const values = allKeys.map((k) => { var _a, _b; return (_b = (_a = item[k]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : ""; });
|
|
560
|
+
const compositeValue = values.join(">");
|
|
561
|
+
const key = compositeValue; // unique per composite
|
|
562
|
+
if (!groupsMap.has(key)) {
|
|
563
|
+
groupsMap.set(key, {
|
|
564
|
+
key: lastKey,
|
|
565
|
+
value: compositeValue,
|
|
566
|
+
count: 0,
|
|
567
|
+
subGroups: [],
|
|
568
|
+
values: [],
|
|
569
|
+
allKeys: allKeys,
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
const group = groupsMap.get(key);
|
|
573
|
+
group.values.push(item);
|
|
574
|
+
});
|
|
575
|
+
const groupedResult = Array.from(groupsMap.values());
|
|
576
|
+
groupedResult.forEach((group) => {
|
|
577
|
+
group.count = group.values.length;
|
|
578
|
+
// Put items as subGroups so the flattener emits the row items
|
|
579
|
+
group.subGroups = group.values;
|
|
580
|
+
});
|
|
581
|
+
return groupedResult;
|
|
582
|
+
}
|
|
583
|
+
// Default behavior: nested grouping by each key level-by-level
|
|
552
584
|
const groupData = (items, keys, level = 0) => {
|
|
553
585
|
if (level >= keys.length)
|
|
554
586
|
return items;
|
|
@@ -584,7 +616,11 @@ const Grid = ({ columns, wrapperClass, updateGridColumns, data, height, sortable
|
|
|
584
616
|
if (groupedData) {
|
|
585
617
|
groupedData.forEach((group) => {
|
|
586
618
|
const _groupedValues = [...groupedValues, group.value].map((item) => item ? item : "row");
|
|
587
|
-
|
|
619
|
+
// If composite grouping is used, the group may carry allKeys to
|
|
620
|
+
// indicate the full set of keys for width/alignment purposes
|
|
621
|
+
const currentKeys = (group.allKeys
|
|
622
|
+
? group.allKeys
|
|
623
|
+
: [...parentKeys, group.key]).filter((item) => item);
|
|
588
624
|
const groupedValue = _groupedValues.join(">");
|
|
589
625
|
const groupedKey = currentKeys.join(">");
|
|
590
626
|
if (group.values) {
|
|
@@ -615,9 +651,50 @@ const Grid = ({ columns, wrapperClass, updateGridColumns, data, height, sortable
|
|
|
615
651
|
}
|
|
616
652
|
return flatArray;
|
|
617
653
|
};
|
|
654
|
+
// Support grouping by comma-separated sets, where each set may contain
|
|
655
|
+
// multiple keys separated by "+" to indicate a composite group at that level.
|
|
656
|
+
const groupBySets = (data, groupSets) => {
|
|
657
|
+
const groupLevel = (items, level) => {
|
|
658
|
+
if (level >= groupSets.length)
|
|
659
|
+
return items;
|
|
660
|
+
const keys = groupSets[level];
|
|
661
|
+
const map = new Map();
|
|
662
|
+
const lastKey = keys[keys.length - 1];
|
|
663
|
+
items.forEach((item) => {
|
|
664
|
+
const values = keys.map((k) => { var _a, _b; return (_b = (_a = item[k]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : ""; });
|
|
665
|
+
const composite = values.join(">");
|
|
666
|
+
if (!map.has(composite)) {
|
|
667
|
+
map.set(composite, {
|
|
668
|
+
key: lastKey,
|
|
669
|
+
value: composite,
|
|
670
|
+
count: 0,
|
|
671
|
+
subGroups: [],
|
|
672
|
+
values: [],
|
|
673
|
+
allKeys: keys,
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
const g = map.get(composite);
|
|
677
|
+
g.values.push(item);
|
|
678
|
+
});
|
|
679
|
+
const groups = Array.from(map.values());
|
|
680
|
+
groups.forEach((g) => {
|
|
681
|
+
g.count = g.values.length;
|
|
682
|
+
g.subGroups = groupLevel(g.values, level + 1);
|
|
683
|
+
});
|
|
684
|
+
return groups;
|
|
685
|
+
};
|
|
686
|
+
return groupLevel(data, 0);
|
|
687
|
+
};
|
|
618
688
|
useEffect(() => {
|
|
619
689
|
if (gridGroupBy && gridGroupBy !== "") {
|
|
620
|
-
const
|
|
690
|
+
const sets = gridGroupBy
|
|
691
|
+
.split(",")
|
|
692
|
+
.map((s) => s.trim())
|
|
693
|
+
.filter((s) => s)
|
|
694
|
+
.map((s) => s.split("+").map((k) => k.trim()).filter((k) => k));
|
|
695
|
+
const groupedArray = sets.length
|
|
696
|
+
? groupBySets(sortedData, sets)
|
|
697
|
+
: [];
|
|
621
698
|
const flatGroupedArray = flattenGroupedData(groupedArray, 1);
|
|
622
699
|
setGroupedData(flatGroupedArray);
|
|
623
700
|
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
|
+
/** When multiple keys are chosen for groupBy, treat them as a single composite group instead of nested groups */
|
|
108
|
+
compositeGroupBy?: boolean;
|
|
107
109
|
hlBorderColor?: string;
|
|
108
110
|
selectedRow?: number;
|
|
109
111
|
selectedRowStyle?: React.CSSProperties;
|
package/package.json
CHANGED