@kareemelbalshe/any-table 1.2.0 → 1.3.0

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/CHANGELOG.md CHANGED
@@ -4,6 +4,28 @@ All notable changes to **AnyTable** (`@kareemelbalshe/any-table`) are documented
4
4
 
5
5
  ---
6
6
 
7
+ ## [1.3.0] - 2026-11-16
8
+
9
+ ### 🌟 Enterprise Server-Side Export & Enhancements
10
+ - 📊 **Server-Side Pagination Export (`fetchAllRows`)**:
11
+ - Full support for exporting **all filtered rows** rather than only the current page when server-side pagination is active.
12
+ - Added `exportable.fetchAllRows?: boolean | ((params) => Promise<TData[]>)`. AnyTable automatically passes active search, sorting, and filter parameters to retrieve full filtered results and format them with UTF-8 BOM CSV / JSON.
13
+ - 🚀 **Full-Control Custom Export (`onExport`)**:
14
+ - Added `exportable.onExport?: (format, context) => Promise<void> | void` for enterprise streaming downloads or delegating report generation to backend endpoints.
15
+ - 🎯 **Client-Side Export Enhancement**:
16
+ - Client-side tables now automatically export **all filtered & sorted records** across pages by default instead of only the active page slice.
17
+ - 📐 **Granular Export Scopes & Column Control**:
18
+ - Added `scope?: "all" | "current-page" | "selected" | "auto"`.
19
+ - Added `showScopeOptions?: boolean` to provide scope sub-options in the toolbar dropdown.
20
+ - Added `col.exportable?: boolean` to exclude specific columns from exports.
21
+ - Added `col.exportFormatter?: (value, row) => string` for custom cell values during export without altering React UI renderers.
22
+ - ⏳ **Reactive Export State**:
23
+ - Added `isExporting` state with animated spinner and disabled state on the toolbar button to prevent duplicate export submissions. Exposed on `TableInstance` and `useAnyTable`.
24
+ - 🛡️ **API Stability**:
25
+ - Secured `useAnyTableData` with `apiRef` to prevent re-fetch loops when `api={{ fetcher }}` is defined inline.
26
+
27
+ ---
28
+
7
29
  ## [1.1.0] - 2026-10-13
8
30
 
9
31
  ### 🌟 New Features & Enhancements
package/README.md CHANGED
@@ -277,6 +277,55 @@ const tableRef = useRef<TableInstance>(null);
277
277
  tableRef.current?.exportData("csv", "quarterly-report");
278
278
  ```
279
279
 
280
+ ### ⚡ Server-Side Pagination & Exporting All Filtered Rows
281
+
282
+ When building admin panels with server-side pagination, the frontend only loads the active page (e.g. 10 or 25 rows) out of thousands of records. AnyTable gives you two enterprise-grade patterns to export **all filtered rows**:
283
+
284
+ #### Pattern 1: `fetchAllRows` (Fetch full dataset & let AnyTable generate Excel CSV)
285
+ Provide `fetchAllRows` in `exportable`. AnyTable automatically passes current `search`, `sortBy`, `sortOrder`, and extra parameters, displays a loading spinner on the button, generates the CSV with UTF-8 BOM, and triggers the download:
286
+
287
+ ```tsx
288
+ <AnyTable<User>
289
+ api={{
290
+ fetcher: fetchUsersApi, // server-side pagination (10 per page)
291
+ }}
292
+ exportable={{
293
+ csv: true,
294
+ filename: "filtered-users",
295
+ fetchAllRows: async ({ search, sortBy, sortOrder }) => {
296
+ // Calls your endpoint without pagination limit:
297
+ const res = await axios.get("/api/users/all", {
298
+ params: { search, sortBy, sortOrder },
299
+ });
300
+ return res.data;
301
+ },
302
+ }}
303
+ />
304
+ ```
305
+
306
+ #### Pattern 2: `onExport` (Backend Streaming / Full Control)
307
+ For massive datasets (e.g. 100,000+ rows) where generating in browser memory isn't ideal, delegate the export to your backend:
308
+
309
+ ```tsx
310
+ <AnyTable<Order>
311
+ api={{ fetcher: fetchOrdersApi }}
312
+ exportable={{
313
+ onExport: async (format, context) => {
314
+ const { search, sortBy, sortOrder, totalRecords } = context;
315
+ // Trigger backend report generation or streaming download:
316
+ window.open(`/api/reports/export?format=${format}&search=${search}&sortBy=${sortBy}`);
317
+ },
318
+ }}
319
+ />
320
+ ```
321
+
322
+ #### Advanced Export Options
323
+ - **`scope`**: `"all"` (all filtered rows, default in client mode & when fetchAllRows is set) | `"current-page"` (active page only) | `"selected"` (checkbox-selected rows).
324
+ - **`showScopeOptions: true`**: Exposes scope choices ("All Filtered", "Current Page", "Selected") in the toolbar dropdown.
325
+ - **`col.exportable: false`**: Exclude specific columns (e.g. actions, internal IDs) from the exported file.
326
+ - **`col.exportFormatter: (value, row) => string`**: Custom cell formatting specifically for CSV/Excel without affecting UI renderers.
327
+ - **`isExporting`**: Reactive loading indicator exposed via `useAnyTable` and `tableRef.current?.isExporting`.
328
+
280
329
  ---
281
330
 
282
331
  ## 🌍 First-Class RTL & Internationalization (Arabic & English)
@@ -1,6 +1,6 @@
1
1
  import { default as React } from 'react';
2
2
  import { TableMessages } from '../i18n';
3
- import { ExportConfig } from '../types/table.types';
3
+ import { ExportConfig, ExportScope } from '../types/table.types';
4
4
  export interface TableToolbarProps {
5
5
  displayTitle?: React.ReactNode;
6
6
  subtitle?: React.ReactNode;
@@ -16,7 +16,9 @@ export interface TableToolbarProps {
16
16
  addHandler?: () => void;
17
17
  messages?: TableMessages;
18
18
  exportable?: boolean | ExportConfig;
19
- onExport?: (format: "csv" | "json") => void;
19
+ onExport?: (format: "csv" | "json", scope?: ExportScope) => void;
20
+ isExporting?: boolean;
21
+ hasSelectedRows?: boolean;
20
22
  dir?: "ltr" | "rtl" | "auto";
21
23
  }
22
- export declare function TableToolbar({ displayTitle, subtitle, isSearchEnabled, searchQuery, setSearch, clearSearch, isDebouncing, searchPlaceholder, headerActions, add, linkAdd, addHandler, messages, exportable, onExport, dir, }: TableToolbarProps): React.JSX.Element | null;
24
+ export declare function TableToolbar({ displayTitle, subtitle, isSearchEnabled, searchQuery, setSearch, clearSearch, isDebouncing, searchPlaceholder, headerActions, add, linkAdd, addHandler, messages, exportable, onExport, isExporting, hasSelectedRows, dir, }: TableToolbarProps): React.JSX.Element | null;
@@ -1,4 +1,4 @@
1
- import { RowKeyResolver, SearchConfig, SortingConfig, PaginationConfig, ExportConfig } from '../types/table.types';
1
+ import { RowKeyResolver, SearchConfig, SortingConfig, PaginationConfig, ExportConfig, ExportScope } from '../types/table.types';
2
2
  import { ColumnDef } from '../types/column.types';
3
3
  import { ApiConfig } from '../types/api.types';
4
4
  export interface UseAnyTableOptions<TData = any> {
@@ -12,7 +12,7 @@ export interface UseAnyTableOptions<TData = any> {
12
12
  pagination?: boolean | PaginationConfig;
13
13
  manualLoading?: boolean;
14
14
  onSelectionChange?: (selectedRows: TData[], selectedKeys: (string | number)[]) => void;
15
- exportable?: boolean | ExportConfig;
15
+ exportable?: boolean | ExportConfig<TData>;
16
16
  }
17
17
  export declare function useAnyTable<TData = any>(options?: UseAnyTableOptions<TData>): {
18
18
  rows: TData[];
@@ -21,6 +21,7 @@ export declare function useAnyTable<TData = any>(options?: UseAnyTableOptions<TD
21
21
  loading: boolean;
22
22
  error: any;
23
23
  isServerMode: boolean;
24
+ isExporting: boolean;
24
25
  refresh: () => Promise<void>;
25
26
  reset: () => void;
26
27
  search: {
@@ -59,5 +60,5 @@ export declare function useAnyTable<TData = any>(options?: UseAnyTableOptions<TD
59
60
  allSelected: boolean;
60
61
  isIndeterminate: boolean;
61
62
  };
62
- exportData: (format?: "csv" | "json", filename?: string) => void;
63
+ exportData: (format?: "csv" | "json", filename?: string, scopeOverride?: ExportScope) => Promise<void>;
63
64
  };
@@ -1,5 +1,5 @@
1
1
  import { default as React } from 'react';
2
- import { TableInstance, TableState } from '../types/table.types';
2
+ import { TableInstance, TableState, ExportScope } from '../types/table.types';
3
3
  import { SortDirection } from '../types/column.types';
4
4
  export interface UseAnyTableControllerParams<TData = any> {
5
5
  tableRef?: React.Ref<TableInstance<TData>>;
@@ -15,6 +15,7 @@ export interface UseAnyTableControllerParams<TData = any> {
15
15
  clearSelection: () => void;
16
16
  getState: () => TableState<TData>;
17
17
  scrollToIndex?: (index: number, align?: "start" | "center" | "end" | "auto") => void;
18
- exportData?: (format?: "csv" | "json", filename?: string) => void;
18
+ exportData?: (format?: "csv" | "json", filename?: string, scope?: ExportScope) => Promise<void>;
19
+ isExporting?: boolean;
19
20
  }
20
- export declare function useAnyTableController<TData = any>({ tableRef, refresh, resetPagination, resetSearch, resetSorting, setPage, setPageSize, setSearch, setSorting, selectedRows, clearSelection, getState, scrollToIndex, exportData, }: UseAnyTableControllerParams<TData>): void;
21
+ export declare function useAnyTableController<TData = any>({ tableRef, refresh, resetPagination, resetSearch, resetSorting, setPage, setPageSize, setSearch, setSorting, selectedRows, clearSelection, getState, scrollToIndex, exportData, isExporting, }: UseAnyTableControllerParams<TData>): void;
@@ -14,6 +14,7 @@ export interface UseAnyTableDataParams<TData = any> {
14
14
  }
15
15
  export declare function useAnyTableData<TData = any>({ data: directData, api, columns, searchQuery, sortBy, sortOrder, page, pageSize, paginationEnabled, manualLoading, }: UseAnyTableDataParams<TData>): {
16
16
  rows: TData[];
17
+ allFilteredRows: TData[];
17
18
  totalRecords: number;
18
19
  loading: boolean;
19
20
  error: any;
@@ -16,6 +16,10 @@ export interface TableMessages {
16
16
  exportCsv: string;
17
17
  exportJson: string;
18
18
  exportSuccess: string;
19
+ exporting: string;
20
+ exportAll: string;
21
+ exportCurrentPage: string;
22
+ exportSelected: string;
19
23
  selectAll: string;
20
24
  selectRow: string;
21
25
  prevPage: string;