@megha-ui/react 1.2.752 → 1.2.754

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,5 @@
1
1
  import { DataRow } from "../types/grid";
2
- export declare const usePagination: (sortedData: DataRow[], defaultRowsPerPage: number) => {
2
+ export declare const usePagination: (sortedData: DataRow[], defaultRowsPerPage: number, currentPageProp: number | undefined, getCurrentPage: (page: number) => void, totalPages: number) => {
3
3
  paginatedData: DataRow[];
4
4
  currentPage: number;
5
5
  handleChangePage: (page: number) => void;
@@ -1,7 +1,15 @@
1
1
  import { useState, useMemo, useEffect } from "react";
2
- export const usePagination = (sortedData, defaultRowsPerPage) => {
2
+ export const usePagination = (sortedData, defaultRowsPerPage, currentPageProp, getCurrentPage, totalPages) => {
3
3
  const [currentPage, setCurrentPage] = useState(1);
4
4
  const [rowsPerPage, setRowsPerPage] = useState(10);
5
+ useEffect(() => {
6
+ if (currentPageProp !== undefined && currentPageProp >= 1 && currentPageProp <= totalPages) {
7
+ setCurrentPage(currentPageProp);
8
+ }
9
+ else {
10
+ setCurrentPage(1);
11
+ }
12
+ }, [currentPageProp]);
5
13
  useEffect(() => {
6
14
  setRowsPerPage(defaultRowsPerPage);
7
15
  }, [defaultRowsPerPage]);
@@ -11,7 +19,7 @@ export const usePagination = (sortedData, defaultRowsPerPage) => {
11
19
  }, [sortedData, currentPage, rowsPerPage]);
12
20
  const handleChangePage = (page) => {
13
21
  setCurrentPage(page);
14
- localStorage.setItem("currentPage", page.toString());
22
+ getCurrentPage(page);
15
23
  };
16
24
  const handleChangeRowsPerPage = (value) => {
17
25
  setRowsPerPage(parseInt(value.toString(), 10));
@@ -40,7 +40,9 @@ const Grid = ({ columns, wrapperClass, updateGridColumns, data, height, sortable
40
40
  console.log("Update fixed filter values not implemented", fixedFilterValues);
41
41
  }, locale, formatOptions, exportOptions,
42
42
  // Card wrapper props
43
- withCard = false, cardClassName, cardHeader, title, headerLeft, headerRight, subHeader, cardFooter }) => {
43
+ withCard = false, cardClassName, cardHeader, title, headerLeft, headerRight, subHeader, cardFooter, getCurrentPage = (page) => {
44
+ console.log("Current page:", page);
45
+ }, currentPage: propCurrentPage, }) => {
44
46
  var _a, _b, _c, _d;
45
47
  const [searchQueries, setSearchQueries] = useState({});
46
48
  const [chips, setChips] = useState([]);
@@ -530,8 +532,9 @@ withCard = false, cardClassName, cardHeader, title, headerLeft, headerRight, sub
530
532
  setSummariseKeys(_summariseKeys);
531
533
  setSummariseDetails(newSummariseDetails);
532
534
  };
535
+ const [totalPages, setTotalPages] = useState(0);
533
536
  const { sortedData, handleSort, sortQueries, setSortQueries } = useSort(filteredData, gridColumns, uniqueSearch, multiSorting, withAscii);
534
- const { paginatedData, currentPage, handleChangePage, handleChangeRowsPerPage, rowsPerPage, } = usePagination(sortedData, defaultRowsPerPage);
537
+ const { paginatedData, currentPage, handleChangePage, handleChangeRowsPerPage, rowsPerPage, } = usePagination(sortedData, defaultRowsPerPage, propCurrentPage, getCurrentPage, totalPages);
535
538
  useEffect(() => {
536
539
  const keys = Object.keys(summariseKeys);
537
540
  if (keys.length > 0 && summariseAvailable) {
@@ -544,7 +547,6 @@ withCard = false, cardClassName, cardHeader, title, headerLeft, headerRight, sub
544
547
  setSelectedRows: setSelectedCheckbox,
545
548
  });
546
549
  const [hasVerticalScroll, setHasVerticalScroll] = useState(false);
547
- const [totalPages, setTotalPages] = useState(0);
548
550
  const [rowOpened, setRowOpened] = useState([]);
549
551
  const gridRef = useRef(null);
550
552
  const entrieGridRef = useRef(null);
@@ -855,7 +857,6 @@ withCard = false, cardClassName, cardHeader, title, headerLeft, headerRight, sub
855
857
  };
856
858
  }, [sortedData, paginate, paginatedData]);
857
859
  useEffect(() => {
858
- handleChangePage(1);
859
860
  setTotalPages(getTotalPages(sortedData.length, rowsPerPage));
860
861
  }, [data, sortQueries, rowsPerPage, sortedData.length]);
861
862
  const isScrollAlmostAtEnd = (element, threshold = 100) => {
@@ -172,6 +172,8 @@ export interface OjasGridProps {
172
172
  headerRight?: ReactNode;
173
173
  subHeader?: ReactNode;
174
174
  cardFooter?: ReactNode;
175
+ getCurrentPage?: (page: number) => void;
176
+ currentPage?: number;
175
177
  }
176
178
  export interface GroupedRowProps {
177
179
  item: any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@megha-ui/react",
3
- "version": "1.2.752",
3
+ "version": "1.2.754",
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",