@megha-ui/react 1.2.754 → 1.2.755

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.
@@ -1,5 +1,11 @@
1
1
  import { Column, DataRow } from "../types/grid";
2
- export declare const useSort: (data: DataRow[], columns: Column[], uniqueSearch: any, multiSorting: boolean, withAscii: boolean) => {
2
+ export declare const useSort: (data: DataRow[], columns: Column[], uniqueSearch: any, multiSorting: boolean, withAscii: boolean, combinedColumns?: {
3
+ name: string;
4
+ key: string;
5
+ separator: string;
6
+ columns: string[];
7
+ sortOn: string[];
8
+ }[]) => {
3
9
  sortedData: DataRow[];
4
10
  handleSort: (column: Column | null, order?: "asc" | "desc") => void;
5
11
  sortQueries: {
@@ -1,14 +1,14 @@
1
1
  import { useState, useMemo } from "react";
2
- export const useSort = (data, columns, uniqueSearch, multiSorting, withAscii) => {
2
+ export const useSort = (data, columns, uniqueSearch, multiSorting, withAscii, combinedColumns) => {
3
3
  const [sortQueries, setSortQueries] = useState({});
4
4
  const hierarchicalSort = (keys, orders) => {
5
5
  return (a, b) => {
6
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
6
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
7
7
  for (let i = 0; i < keys.length; i++) {
8
8
  const key = keys[i];
9
9
  const column = columns.find((col) => col.key === key);
10
10
  const order = orders[i] === "asc" ? 1 : -1;
11
- const aValue = ((_a = a[key]) === null || _a === void 0 ? void 0 : _a.value)
11
+ let aValue = ((_a = a[key]) === null || _a === void 0 ? void 0 : _a.value)
12
12
  ? (column === null || column === void 0 ? void 0 : column.dataType) &&
13
13
  ((column === null || column === void 0 ? void 0 : column.dataType) === "number" || (column === null || column === void 0 ? void 0 : column.dataType) === "currency")
14
14
  ? parseFloat((_c = (_b = a[key]) === null || _b === void 0 ? void 0 : _b.value) === null || _c === void 0 ? void 0 : _c.toString())
@@ -18,7 +18,7 @@ export const useSort = (data, columns, uniqueSearch, multiSorting, withAscii) =>
18
18
  : (column === null || column === void 0 ? void 0 : column.dataType) === "number" || (column === null || column === void 0 ? void 0 : column.dataType) === "currency"
19
19
  ? 0
20
20
  : "";
21
- const bValue = ((_h = b[key]) === null || _h === void 0 ? void 0 : _h.value)
21
+ let bValue = ((_h = b[key]) === null || _h === void 0 ? void 0 : _h.value)
22
22
  ? (column === null || column === void 0 ? void 0 : column.dataType) &&
23
23
  ((column === null || column === void 0 ? void 0 : column.dataType) === "number" || (column === null || column === void 0 ? void 0 : column.dataType) === "currency")
24
24
  ? parseFloat((_k = (_j = b[key]) === null || _j === void 0 ? void 0 : _j.value) === null || _k === void 0 ? void 0 : _k.toString())
@@ -28,6 +28,30 @@ export const useSort = (data, columns, uniqueSearch, multiSorting, withAscii) =>
28
28
  : (column === null || column === void 0 ? void 0 : column.dataType) === "number" || (column === null || column === void 0 ? void 0 : column.dataType) === "currency"
29
29
  ? 0
30
30
  : "";
31
+ if (combinedColumns && (combinedColumns === null || combinedColumns === void 0 ? void 0 : combinedColumns.length) > 0) {
32
+ const combinedColumn = combinedColumns.find((col) => col.key === key);
33
+ if (combinedColumn) {
34
+ const { columns: combinedCols, separator, sortOn } = combinedColumn;
35
+ if (sortOn) {
36
+ const index = combinedCols.findIndex((colKey) => colKey === sortOn[0]);
37
+ const aVals = (((_r = (_q = a[key]) === null || _q === void 0 ? void 0 : _q.value) === null || _r === void 0 ? void 0 : _r.toString()) || "").split(separator);
38
+ const bVals = (((_t = (_s = b[key]) === null || _s === void 0 ? void 0 : _s.value) === null || _t === void 0 ? void 0 : _t.toString()) || "").split(separator);
39
+ aValue = aVals[index] || "";
40
+ bValue = bVals[index] || "";
41
+ if (parseFloat(aValue).toString() !== "NaN" &&
42
+ parseFloat(bValue).toString() !== "NaN") {
43
+ aValue = parseFloat(aValue);
44
+ bValue = parseFloat(bValue);
45
+ }
46
+ else {
47
+ if (!withAscii) {
48
+ aValue = aValue.toUpperCase();
49
+ bValue = bValue.toUpperCase();
50
+ }
51
+ }
52
+ }
53
+ }
54
+ }
31
55
  if (aValue < bValue)
32
56
  return -1 * order;
33
57
  if (aValue > bValue)
@@ -42,7 +42,7 @@ const Grid = ({ columns, wrapperClass, updateGridColumns, data, height, sortable
42
42
  // Card wrapper props
43
43
  withCard = false, cardClassName, cardHeader, title, headerLeft, headerRight, subHeader, cardFooter, getCurrentPage = (page) => {
44
44
  console.log("Current page:", page);
45
- }, currentPage: propCurrentPage, }) => {
45
+ }, currentPage: propCurrentPage, combinedColumns, }) => {
46
46
  var _a, _b, _c, _d;
47
47
  const [searchQueries, setSearchQueries] = useState({});
48
48
  const [chips, setChips] = useState([]);
@@ -533,7 +533,7 @@ withCard = false, cardClassName, cardHeader, title, headerLeft, headerRight, sub
533
533
  setSummariseDetails(newSummariseDetails);
534
534
  };
535
535
  const [totalPages, setTotalPages] = useState(0);
536
- const { sortedData, handleSort, sortQueries, setSortQueries } = useSort(filteredData, gridColumns, uniqueSearch, multiSorting, withAscii);
536
+ const { sortedData, handleSort, sortQueries, setSortQueries } = useSort(filteredData, gridColumns, uniqueSearch, multiSorting, withAscii, combinedColumns);
537
537
  const { paginatedData, currentPage, handleChangePage, handleChangeRowsPerPage, rowsPerPage, } = usePagination(sortedData, defaultRowsPerPage, propCurrentPage, getCurrentPage, totalPages);
538
538
  useEffect(() => {
539
539
  const keys = Object.keys(summariseKeys);
@@ -174,6 +174,13 @@ export interface OjasGridProps {
174
174
  cardFooter?: ReactNode;
175
175
  getCurrentPage?: (page: number) => void;
176
176
  currentPage?: number;
177
+ combinedColumns?: {
178
+ name: string;
179
+ key: string;
180
+ separator: string;
181
+ columns: string[];
182
+ sortOn: string[];
183
+ }[];
177
184
  }
178
185
  export interface GroupedRowProps {
179
186
  item: any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@megha-ui/react",
3
- "version": "1.2.754",
3
+ "version": "1.2.755",
4
4
  "description": "A collection of reusable UI components for React applications, built with TypeScript.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",