@reactorui/datagrid 1.2.0 → 1.2.1

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.
@@ -21,7 +21,7 @@ interface UseDataGridProps<T> {
21
21
  onClearFilters?: () => void;
22
22
  onFilterChange?: (filters: ActiveFilter[]) => void;
23
23
  }
24
- export declare const useDataGrid: <T extends BaseRowData>({ data, pageSize: initialPageSize, totalRecords: externalTotalRecords, currentPage: externalCurrentPage, loading: externalLoading, filterMode, onPageChange, onPageSizeChange, onSortChange, onSearchChange, onApplyFilter, onRemoveFilter, onClearFilters, onFilterChange, }: UseDataGridProps<T>) => {
24
+ export declare const useDataGrid: <T extends BaseRowData>({ data, pageSize, totalRecords: externalTotalRecords, currentPage: externalCurrentPage, loading: externalLoading, filterMode, onPageChange, onPageSizeChange, onSortChange, onSearchChange, onApplyFilter, onRemoveFilter, onClearFilters, onFilterChange, }: UseDataGridProps<T>) => {
25
25
  data: T[];
26
26
  processedData: T[];
27
27
  paginatedData: T[];
@@ -1 +1 @@
1
- {"version":3,"file":"useDataGrid.d.ts","sourceRoot":"","sources":["../../src/hooks/useDataGrid.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAOjF,UAAU,gBAAgB,CAAC,CAAC;IAC1B,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,QAAQ,CAAC,EAAE,MAAM,CAAC;IAGlB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,eAAe,CAAC;IAGnD,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,KAAK,IAAI,CAAC;IAC5D,gBAAgB,CAAC,E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QAAQ,GAAG,QAAQ,GAAG,eAAe,CAAC;IAGnD,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,KAAK,IAAI,CAAC;IAC5D,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;IAC5C,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,YAAY,EAAE,KAAK,IAAI,CAAC;IACpE,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,KAAK,IAAI,CAAC;IAC5E,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;IAC5B,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,IAAI,CAAC;CACpD;AAMD,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,WAAW,EAAE,8PAehD,gBAAgB,CAAC,CAAC,CAAC;;;;;;;;;;;0BAkHX,MAAM;sBASJ,MAAM;2BAaR,MAAM;+BAQN,MAAM;;;wBAsBJ,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC;0BAoB5B,MAAM;;uBA4BsB,MAAM,YAAY,OAAO;0BASlD,OAAO;;;;;;oBA3LZ,CAAC,KAAG,MAAM;;CA2PnB,CAAC"}
@@ -1,17 +1,22 @@
1
1
  // File: src/hooks/useDataGrid.ts
2
- import { useState, useCallback, useMemo } from 'react';
2
+ import { useState, useCallback, useMemo, useEffect } from 'react';
3
3
  import { compareValues, sortData } from '../utils';
4
4
  // ============================================================================
5
5
  // Hook Implementation
6
6
  // ============================================================================
7
- export const useDataGrid = ({ data, pageSize: initialPageSize = 10, totalRecords: externalTotalRecords, currentPage: externalCurrentPage, loading: externalLoading = false, filterMode = 'client', onPageChange, onPageSizeChange, onSortChange, onSearchChange, onApplyFilter, onRemoveFilter, onClearFilters, onFilterChange, }) => {
7
+ export const useDataGrid = ({ data, pageSize = 10, totalRecords: externalTotalRecords, currentPage: externalCurrentPage, loading: externalLoading = false, filterMode = 'client', onPageChange, onPageSizeChange, onSortChange, onSearchChange, onApplyFilter, onRemoveFilter, onClearFilters, onFilterChange, }) => {
8
8
  // ===== Internal State =====
9
9
  const [searchTerm, setSearchTermState] = useState('');
10
10
  const [activeFilters, setActiveFilters] = useState([]);
11
11
  const [sortConfig, setSortConfig] = useState({ column: '', direction: 'asc' });
12
12
  const [selectedRows, setSelectedRows] = useState(new Set());
13
13
  const [internalPage, setInternalPage] = useState(1);
14
- const [currentPageSize, setCurrentPageSizeState] = useState(initialPageSize);
14
+ const [currentPageSize, setCurrentPageSizeState] = useState(pageSize);
15
+ // ===== Sync pageSize prop with internal state =====
16
+ // This ensures the component responds to prop changes from parent
17
+ useEffect(() => {
18
+ setCurrentPageSizeState(pageSize);
19
+ }, [pageSize]);
15
20
  // Determine if we're in controlled mode (server-side) or uncontrolled (client-side)
16
21
  const isControlled = externalTotalRecords !== undefined;
17
22
  const currentPage = externalCurrentPage ?? internalPage;
@@ -68,9 +73,10 @@ export const useDataGrid = ({ data, pageSize: initialPageSize = 10, totalRecords
68
73
  const start = (currentPage - 1) * currentPageSize;
69
74
  return processedData.slice(start, start + currentPageSize);
70
75
  }, [processedData, currentPage, currentPageSize, isControlled, data]);
76
+ // ===== Pagination Info =====
71
77
  const paginationInfo = useMemo(() => {
72
78
  const total = isControlled ? (externalTotalRecords ?? 0) : processedData.length;
73
- const totalPages = Math.ceil(total / currentPageSize);
79
+ const totalPages = Math.ceil(total / currentPageSize) || 1;
74
80
  const start = total === 0 ? 0 : (currentPage - 1) * currentPageSize + 1;
75
81
  const end = Math.min(currentPage * currentPageSize, total);
76
82
  return {
@@ -83,7 +89,7 @@ export const useDataGrid = ({ data, pageSize: initialPageSize = 10, totalRecords
83
89
  hasNext: currentPage < totalPages,
84
90
  hasPrevious: currentPage > 1,
85
91
  };
86
- }, [processedData.length, currentPage, currentPageSize, isControlled, externalTotalRecords]);
92
+ }, [processedData, currentPage, currentPageSize, isControlled, externalTotalRecords]);
87
93
  // ===== Selection =====
88
94
  const selectedData = useMemo(() => {
89
95
  return data.filter((row) => selectedRows.has(getRowId(row)));
@@ -113,7 +119,7 @@ export const useDataGrid = ({ data, pageSize: initialPageSize = 10, totalRecords
113
119
  const setCurrentPageSize = useCallback((size) => {
114
120
  setCurrentPageSizeState(size);
115
121
  if (!isControlled)
116
- setInternalPage(1);
122
+ setInternalPage(1); // Reset to page 1 when page size changes
117
123
  onPageSizeChange?.(size);
118
124
  }, [isControlled, onPageSizeChange]);
119
125
  const navigateNext = useCallback(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactorui/datagrid",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "A flexible, high-performance React data grid component with TypeScript support, advanced filtering, pagination, sorting, and customizable theming",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",