jattac.libs.web.responsive-table 0.7.5 → 0.8.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/README.md CHANGED
@@ -1,1095 +1,58 @@
1
- # ResponsiveTable: A Modern and Flexible React Table Component
2
-
3
- ResponsiveTable is a powerful, lightweight, and fully responsive React component for creating beautiful and functional tables. It’s designed to look great on any device, adapting from a traditional table layout on desktops to a clean, card-based view on mobile screens.
4
-
5
- ## Table of Contents
6
-
7
- - [Features](#features)
8
- - [Installation](#installation)
9
- - [Getting Started](#getting-started)
10
- - [Comprehensive Examples](#comprehensive-examples)
11
- - [Example 1: Loading State and Animations](#example-1-loading-state-and-animations)
12
- - [Example 2: Adding a Clickable Row Action](#example-2-adding-a-clickable-row-action)
13
- - [Example 3: Row Selection](#example-3-row-selection)
14
- - [Example 4: Custom Cell Rendering](#example-4-custom-cell-rendering)
15
- - [Example 5: Dynamic and Conditional Columns](#example-5-dynamic-and-conditional-columns)
16
- - [Example 6: Advanced Footer with Labels and Interactivity](#example-6-advanced-footer-with-labels-and-interactivity)
17
- - [Example 7: Disabling Page-Level Sticky Header](#example-7-disabling-page-level-sticky-header)
18
- - [Plugin System](#plugin-system)
19
- - [Plugin Execution Order](#plugin-execution-order)
20
- - [How to Use Plugins](#how-to-use-plugins)
21
- - [Built-in Plugins](#built-in-plugins)
22
- - [API Reference](#api-reference)
23
- - [ResponsiveTable Props](#responsivetable-props)
24
- - [IResponsiveTableColumnDefinition<TData>](#iresponsivetablecolumndefinitiontdata)
25
- - [IFooterRowDefinition](#ifooterrowdefinition)
26
- - [IFooterColumnDefinition](#ifootercolumndefinition)
27
- - [Breaking Changes](#breaking-changes)
28
- - [Version 0.5.0](#version-050)
29
- - [License](#license)
30
-
31
- ## Features
32
-
33
- - **Mobile-First Design**: Automatically switches to a card layout on smaller screens for optimal readability.
34
- - **Highly Customizable**: Tailor the look and feel of columns, headers, and footers.
35
- - **Dynamic Data Handling**: Define columns and footers based on your data or application state.
36
- - **Delightful Animations**: Includes an optional skeleton loader and staggered row entrance animations.
37
- - **Interactive Elements**: Easily add click handlers for rows, headers, and footer cells.
38
- - **Row Selection**: Built-in support for single or multiple row selection, with full programmatic control.
39
- - **Efficient & Responsive**: Built with efficiency in mind, including debounced resize handling for smooth transitions.
40
- - **Easy to Use**: A simple and intuitive API for quick integration.
41
- - **Extensible Plugin System**: Easily add new functionalities like filtering, sorting, or infinite scrolling.
42
-
43
- ## Installation
44
-
45
- To get started, install the package from npm:
46
-
47
- ```bash
48
- npm install jattac.libs.web.responsive-table
49
- ```
50
-
51
- ## Getting Started
52
-
53
- Here’s a basic example to get you up and running in minutes.
54
-
55
- ```jsx
56
- import React from 'react';
57
- import ResponsiveTable from 'jattac.libs.web.responsive-table';
58
-
59
- const GettingStarted = () => {
60
- const columns = [
61
- { displayLabel: 'Name', dataKey: 'name', cellRenderer: (row) => row.name },
62
- { displayLabel: 'Age', dataKey: 'age', cellRenderer: (row) => row.age },
63
- { displayLabel: 'City', dataKey: 'city', cellRenderer: (row) => row.city },
64
- ];
65
-
66
- const data = [
67
- { name: 'Alice', age: 32, city: 'New York' },
68
- { name: 'Bob', age: 28, city: 'Los Angeles' },
69
- { name: 'Charlie', age: 45, city: 'Chicago' },
70
- ];
71
-
72
- return <ResponsiveTable columnDefinitions={columns} data={data} />;
73
- };
74
-
75
- export default GettingStarted;
76
- ```
77
-
78
- This will render a table that automatically adapts to the screen size. On a desktop, it will look like a standard table, and on mobile, it will switch to a card-based layout.
79
-
80
- ---
81
-
82
- ## Comprehensive Examples
83
-
84
- ### Example 1: Loading State and Animations
85
-
86
- You can provide a seamless user experience by showing a skeleton loader while your data is being fetched, and then animating the rows in when the data is ready.
87
-
88
- ```jsx
89
- import React, { useState, useEffect } from 'react';
90
- import ResponsiveTable from 'jattac.libs.web.responsive-table';
91
-
92
- const AnimatedTable = () => {
93
- const [data, setData] = useState([]);
94
- const [isLoading, setIsLoading] = useState(true);
95
-
96
- const columns = [
97
- { displayLabel: 'User', cellRenderer: (row) => row.name },
98
- { displayLabel: 'Email', cellRenderer: (row) => row.email },
99
- ];
100
-
101
- useEffect(() => {
102
- // Simulate a network request
103
- setTimeout(() => {
104
- setData([
105
- { name: 'Grace', email: 'grace@example.com' },
106
- { name: 'Henry', email: 'henry@example.com' },
107
- ]);
108
- setIsLoading(false);
109
- }, 2000);
110
- }, []);
111
-
112
- return (
113
- <ResponsiveTable columnDefinitions={columns} data={data} animationProps={{ isLoading, animateOnLoad: true }} />
114
- );
115
- };
116
- ```
117
-
118
- ### Example 2: Adding a Clickable Row Action
119
-
120
- You can make rows clickable to perform actions, such as navigating to a details page or opening a modal.
121
-
122
- ```jsx
123
- import React from 'react';
124
- import ResponsiveTable from 'jattac.libs.web.responsive-table';
125
-
126
- const ClickableRows = () => {
127
- const columns = [
128
- { displayLabel: 'Product', cellRenderer: (row) => row.product },
129
- { displayLabel: 'Price', cellRenderer: (row) => `${row.price.toFixed(2)}` },
130
- ];
131
-
132
- const data = [
133
- { id: 1, product: 'Laptop', price: 1200 },
134
- { id: 2, product: 'Keyboard', price: 75 },
135
- ];
136
-
137
- const handleRowClick = (item) => {
138
- alert(`You clicked on product ID: ${item.id}`);
139
- };
140
-
141
- return <ResponsiveTable columnDefinitions={columns} data={data} onRowClick={handleRowClick} />;
142
- };
143
- ```
144
-
145
- ### Example 3: Row Selection
146
-
147
- Enable row selection by providing the `selectionProps` object. The table can be a fully "controlled" component, where you manage the state of selected items, or an "uncontrolled" component where the table manages its own state.
148
-
149
- #### Controlled Mode (Recommended)
150
-
151
- This pattern gives you full programmatic control over which rows are selected. You manage the selection state in your component and pass it down to the table.
152
-
153
- ```jsx
154
- import React, { useState } from 'react';
155
- import ResponsiveTable from 'jattac.libs.web.responsive-table';
156
-
157
- const ControlledSelectionTable = () => {
158
- const columns = [
159
- { displayLabel: 'Task', dataKey: 'task', cellRenderer: (row) => row.task },
160
- { displayLabel: 'Status', dataKey: 'status', cellRenderer: (row) => row.status },
161
- ];
162
-
163
- const initialData = [
164
- { id: 'task-1', task: 'Design new logo', status: 'In Progress' },
165
- { id: 'task-2', task: 'Develop homepage', status: 'Completed' },
166
- { id: 'task-3', task: 'Write documentation', status: 'Pending' },
167
- { id: 'task-4', task: 'Deploy to production', status: 'Pending' },
168
- ];
169
-
170
- // 1. Manage the selection state in your component
171
- const [selected, setSelected] = useState([initialData[1]]); // Initially select the second row
172
-
173
- const handleSelectionChange = (selectedItems) => {
174
- // 2. Update your state when the selection changes
175
- setSelected(selectedItems);
176
- console.log('Selected items:', selectedItems);
177
- };
178
-
179
- return (
180
- <div>
181
- <button onClick={() => setSelected([])} style={{ marginBottom: '1rem' }}>
182
- Clear Selection
183
- </button>
184
- <ResponsiveTable
185
- columnDefinitions={columns}
186
- data={initialData}
187
- selectionProps={{
188
- onSelectionChange: handleSelectionChange,
189
- selectedItems: selected, // 3. Pass the state down to the table
190
- rowIdKey: 'id', // 4. Provide a unique key for each row
191
- mode: 'multiple',
192
- }}
193
- />
194
- <div style={{ marginTop: '1rem' }}>
195
- <strong>Selected Tasks:</strong>
196
- <ul>
197
- {selected.map((item) => (
198
- <li key={item.id}>{item.task}</li>
199
- ))}
200
- </ul>
201
- </div>
202
- </div>
203
- );
204
- };
205
- ```
206
-
207
- #### Uncontrolled Mode
208
-
209
- This pattern is simpler if you only need to be notified when the selection changes, but don't need to programmatically control the selection from outside the table. The table manages its own selection state internally.
210
-
211
- ```jsx
212
- import React from 'react';
213
- import ResponsiveTable from 'jattac.libs.web.responsive-table';
214
-
215
- const UncontrolledSelectionTable = () => {
216
- const columns = [
217
- { displayLabel: 'User', dataKey: 'name', cellRenderer: (row) => row.name },
218
- { displayLabel: 'Email', dataKey: 'email', cellRenderer: (row) => row.email },
219
- ];
220
-
221
- const data = [
222
- { id: 1, name: 'Diana', email: 'diana@example.com' },
223
- { id: 2, name: 'Ethan', email: 'ethan@example.com' },
224
- { id: 3, name: 'Fiona', email: 'fiona@example.com' },
225
- ];
226
-
227
- const handleSelectionChange = (selectedItems) => {
228
- console.log('Selected items:', selectedItems);
229
- };
230
-
231
- return (
232
- <ResponsiveTable
233
- columnDefinitions={columns}
234
- data={data}
235
- selectionProps={{
236
- onSelectionChange: handleSelectionChange,
237
- rowIdKey: 'id',
238
- // Note: The `selectedItems` prop is omitted
239
- }}
240
- />
241
- );
242
- };
243
- ```
244
-
245
- #### Single Selection Mode
246
-
247
- To allow only one row to be selected at a time, set `mode: 'single'`.
248
-
249
- ```jsx
250
- import React, { useState } from 'react';
251
- import ResponsiveTable from 'jattac.libs.web.responsive-table';
252
-
253
- const SingleSelectionTable = () => {
254
- const columns = [
255
- { displayLabel: 'Flight', dataKey: 'flight', cellRenderer: (row) => row.flight },
256
- { displayLabel: 'Destination', dataKey: 'dest', cellRenderer: (row) => row.dest },
257
- ];
258
-
259
- const data = [
260
- { id: 'fl-101', flight: 'UA 456', dest: 'Tokyo' },
261
- { id: 'fl-102', flight: 'DL 789', dest: 'London' },
262
- { id: 'fl-103', flight: 'AA 123', dest: 'Sydney' },
263
- ];
264
-
265
- const [selectedFlight, setSelectedFlight] = useState([]);
266
-
267
- return (
268
- <div>
269
- <ResponsiveTable
270
- columnDefinitions={columns}
271
- data={data}
272
- selectionProps={{
273
- onSelectionChange: setSelectedFlight,
274
- selectedItems: selectedFlight,
275
- rowIdKey: 'id',
276
- mode: 'single', // Set the mode to single
277
- }}
278
- />
279
- <div style={{ marginTop: '1rem' }}>
280
- <strong>Selected Flight:</strong>
281
- <p>{selectedFlight.length > 0 ? `${selectedFlight[0].flight} to ${selectedFlight[0].dest}` : 'None'}</p>
282
- </div>
283
- </div>
284
- );
285
- };
286
- ```
287
-
288
- > **Note on "Select All" Checkbox:**
289
- >
290
- > A "Select All" checkbox in the header is a common requirement for multi-selection tables. While the `SelectionPlugin` provides the core selection logic, implementing a "Select All" UI requires a bit more setup due to the decoupled nature of the plugin system.
291
- >
292
- > The recommended approach is to use the table in **controlled mode** and create a custom column definition for your checkbox. The `displayLabel` would contain the "Select All" checkbox, and its `onChange` handler would call your state update function (e.g., `setSelected`) to select or deselect all items.
293
- >
294
- > This design gives you maximum flexibility. For instance, you can decide whether "Select All" applies to all data or only the currently filtered data (if using the `FilterPlugin`). A future version of this library may include a more integrated "Select All" solution.
295
-
296
-
297
- ### Example 4: Custom Cell Rendering
298
-
299
- You can render any React component inside a cell, allowing for rich content like buttons, links, or status badges.
300
-
301
- ```jsx
302
- import React from 'react';
303
- import ResponsiveTable from 'jattac.libs.web.responsive-table';
304
-
305
- const CustomCells = () => {
306
- const columns = [
307
- { displayLabel: <strong>User</strong>, cellRenderer: (row) => <strong>{row.user}</strong> },
308
- {
309
- displayLabel: 'Status',
310
- cellRenderer: (row) => (
311
- <span
312
- style={{
313
- color: row.status === 'Active' ? 'green' : 'red',
314
- fontWeight: 'bold',
315
- }}
316
- >
317
- {row.status}
318
- </span>
319
- ),
320
- },
321
- {
322
- displayLabel: 'Action',
323
- cellRenderer: (row) => <button onClick={() => alert(`Editing ${row.user}`)}>Edit</button>,
324
- },
325
- ];
326
-
327
- const data = [
328
- { user: 'Eve', status: 'Active' },
329
- { user: 'Frank', status: 'Inactive' },
330
- ];
331
-
332
- return <ResponsiveTable columnDefinitions={columns} data={data} />;
333
- };
334
- ```
335
-
336
- ### Example 5: Dynamic and Conditional Columns
337
-
338
- Columns can be generated dynamically based on your data or application state. This is useful for creating flexible tables that adapt to different datasets.
339
-
340
- ```jsx
341
- import React from 'react';
342
- import ResponsiveTable from 'jattac.libs.web.responsive-table';
343
-
344
- const DynamicColumns = ({ isAdmin }) => {
345
- // Base columns for all users
346
- const columns = [
347
- { displayLabel: 'File Name', cellRenderer: (row) => row.fileName },
348
- { displayLabel: 'Size', cellRenderer: (row) => `${row.size} KB` },
349
- ];
350
-
351
- // Add an admin-only column conditionally
352
- if (isAdmin) {
353
- columns.push({
354
- displayLabel: 'Admin Actions',
355
- cellRenderer: (row) => <button onClick={() => alert(`Deleting ${row.fileName}`)}>Delete</button>,
356
- });
357
- }
358
-
359
- const data = [
360
- { fileName: 'document.pdf', size: 1024 },
361
- { fileName: 'image.jpg', size: 512 },
362
- ];
363
-
364
- return <ResponsiveTable columnDefinitions={columns} data={data} />;
365
- };
366
- ```
367
-
368
- ### Example 6: Advanced Footer with Labels and Interactivity
369
-
370
- You can add a footer to display summary information, such as totals or averages. The footer is also responsive and will appear correctly in both desktop and mobile views. With the enhanced footer functionality, you can provide explicit labels for mobile view and add click handlers to footer cells.
371
-
372
- ```jsx
373
- import React from 'react';
374
- import ResponsiveTable from 'jattac.libs.web.responsive-table';
375
-
376
- const TableWithFooter = () => {
377
- const columns = [
378
- { displayLabel: 'Item', cellRenderer: (row) => row.item },
379
- { displayLabel: 'Quantity', cellRenderer: (row) => row.quantity },
380
- { displayLabel: 'Price', cellRenderer: (row) => `${row.price.toFixed(2)}` },
381
- ];
382
-
383
- const data = [
384
- { item: 'Apples', quantity: 10, price: 1.5 },
385
- { item: 'Oranges', quantity: 5, price: 2.0 },
386
- { item: 'Bananas', quantity: 15, price: 0.5 },
387
- ];
388
-
389
- const total = data.reduce((sum, row) => sum + row.quantity * row.price, 0);
390
-
391
- const footerRows = [
392
- {
393
- columns: [
394
- {
395
- colSpan: 2,
396
- cellRenderer: () => <strong>Total:</strong>,
397
- },
398
- {
399
- colSpan: 1,
400
- displayLabel: 'Total',
401
- cellRenderer: () => <strong>${total.toFixed(2)}</strong>,
402
- onCellClick: () => alert('Total clicked!'),
403
- },
404
- ],
405
- },
406
- ];
407
-
408
- return <ResponsiveTable columnDefinitions={columns} data={data} footerRows={footerRows} />;
409
- };
410
- ```
411
-
412
- ### Example 7: Disabling Page-Level Sticky Header
413
-
414
- By default, the table header remains fixed to the top of the viewport as the user scrolls down the page. This ensures the column titles are always visible. To disable this behavior and have the header scroll away with the rest of the page, set the `enablePageLevelStickyHeader` prop to `false`.
415
-
416
- ```jsx
417
- import React from 'react';
418
- import ResponsiveTable from 'jattac.libs.web.responsive-table';
419
-
420
- const NonStickyHeaderTable = () => {
421
- // We need enough data to make the page scroll
422
- const data = Array.from({ length: 50 }, (_, i) => ({
423
- id: i + 1,
424
- item: `Item #${i + 1}`,
425
- description: 'This is a sample item.',
426
- }));
427
-
428
- const columns = [
429
- { displayLabel: 'ID', cellRenderer: (row) => row.id },
430
- { displayLabel: 'Item', cellRenderer: (row) => row.item },
431
- { displayLabel: 'Description', cellRenderer: (row) => row.description },
432
- ];
433
-
434
- return (
435
- <div>
436
- <h1 style={{ height: '50vh', display: 'flex', alignItems: 'center' }}>Scroll down to see the table</h1>
437
- <ResponsiveTable
438
- columnDefinitions={columns}
439
- data={data}
440
- enablePageLevelStickyHeader={false} // <-- Here's the magic switch!
441
- />
442
- <div style={{ height: '50vh' }} />
443
- </div>
444
- );
445
- };
446
- ```
447
-
448
- ---
449
-
450
- ## Plugin System
451
-
452
- ResponsiveTable is designed with an extensible plugin system, allowing developers to easily add new functionalities or modify existing behaviors without altering the core component. Plugins can interact with the table's data, render custom UI elements (like headers or footers), and respond to table events.
453
-
454
- ### Plugin Execution Order
455
-
456
- > **Note:** Plugins process data sequentially in the order they are provided in the `plugins` array. This can have important performance and behavioral implications.
457
-
458
- For example, consider the `SortPlugin` and `FilterPlugin`.
459
-
460
- - `plugins={[new SortPlugin(), new FilterPlugin()]}`: This will **sort** the entire dataset first, and then **filter** the sorted data.
461
- - `plugins={[new FilterPlugin(), new SortPlugin()]}`: This will **filter** the dataset first, and then **sort** the much smaller, filtered result.
462
-
463
- For the best performance, it is highly recommended to **filter first, then sort**.
464
-
465
- ### How to Use Plugins
466
-
467
- Plugins are passed to the `ResponsiveTable` component via the `plugins` prop, which accepts an array of `IResponsiveTablePlugin` instances. Some common functionalities, like filtering and infinite scrolling, are provided as built-in plugins that can be enabled via specific props (`filterProps` and `infiniteScrollProps`). When these props are used, the corresponding built-in plugins are automatically initialized if not already provided in the `plugins` array.
468
-
469
- ```jsx
470
- import React from 'react';
471
- // Note: All plugins are exported from the main package entry point.
472
- import ResponsiveTable, { FilterPlugin } from 'jattac.libs.web.responsive-table';
473
-
474
- const MyTableWithPlugins = () => {
475
- const columns = [
476
- { displayLabel: 'Name', dataKey: 'name', cellRenderer: (row) => row.name, getFilterableValue: (row) => row.name },
477
- {
478
- displayLabel: 'Age',
479
- dataKey: 'age',
480
- cellRenderer: (row) => row.age,
481
- getFilterableValue: (row) => row.age.toString(),
482
- },
483
- ];
484
-
485
- const data = [
486
- { name: 'Alice', age: 32 },
487
- { name: 'Bob', age: 28 },
488
- { name: 'Charlie', age: 45 },
489
- ];
490
-
491
- return (
492
- <ResponsiveTable
493
- columnDefinitions={columns}
494
- data={data}
495
- // Enable built-in filter plugin via props
496
- filterProps={{ showFilter: true, filterPlaceholder: 'Search by name or age...' }}
497
- // Or provide a custom instance of the plugin
498
- // plugins={[new FilterPlugin()]}
499
- />
500
- );
501
- };
502
- ```
503
-
504
- ### How to Use Plugins
505
-
506
- Plugins are passed to the `ResponsiveTable` component via the `plugins` prop, which accepts an array of `IResponsiveTablePlugin` instances. Some common functionalities, like filtering and infinite scrolling, are provided as built-in plugins that can be enabled via specific props (`filterProps` and `infiniteScrollProps`). When these props are used, the corresponding built-in plugins are automatically initialized if not already provided in the `plugins` array.
507
-
508
- ```jsx
509
- import React from 'react';
510
- // Note: All plugins are exported from the main package entry point.
511
- import ResponsiveTable, { FilterPlugin } from 'jattac.libs.web.responsive-table';
512
-
513
- const MyTableWithPlugins = () => {
514
- const columns = [
515
- { displayLabel: 'Name', dataKey: 'name', cellRenderer: (row) => row.name, getFilterableValue: (row) => row.name },
516
- {
517
- displayLabel: 'Age',
518
- dataKey: 'age',
519
- cellRenderer: (row) => row.age,
520
- getFilterableValue: (row) => row.age.toString(),
521
- },
522
- ];
523
-
524
- const data = [
525
- { name: 'Alice', age: 32 },
526
- { name: 'Bob', age: 28 },
527
- { name: 'Charlie', age: 45 },
528
- ];
529
-
530
- return (
531
- <ResponsiveTable
532
- columnDefinitions={columns}
533
- data={data}
534
- // Enable built-in filter plugin via props
535
- filterProps={{ showFilter: true, filterPlaceholder: 'Search by name or age...' }}
536
- // Or provide a custom instance of the plugin
537
- // plugins={[new FilterPlugin()]}
538
- />
539
- );
540
- };
541
- ```
542
-
543
- ### Building a Custom Row Selection Plugin
544
-
545
- While `ResponsiveTable` provides built-in plugins for common functionalities like sorting and filtering, its extensible plugin system allows you to create custom plugins for highly specific needs, such as a bespoke row selection mechanism. This guide outlines the steps to build and integrate your own row selection plugin.
546
-
547
- **Step 1: Define Your Plugin Class**
548
-
549
- Create a new TypeScript class that implements the `IResponsiveTablePlugin<TData>` interface. This interface defines the lifecycle methods and hooks your plugin can use to interact with the table.
550
-
551
- ```typescript
552
- // my-custom-selection-plugin.ts
553
- import { IResponsiveTablePlugin, IPluginAPI } from './IResponsiveTablePlugin'; // Adjust path as needed
554
- import styles from './ResponsiveTable.module.css'; // For styling selected rows
555
-
556
- export class MyCustomSelectionPlugin<TData> implements IResponsiveTablePlugin<TData> {
557
- public id = 'my-custom-selection'; // A unique ID for your plugin
558
- private api!: IPluginAPI<TData>;
559
- private selectedRowIds = new Set<string | number>(); // Internal state for selected items
560
-
561
- // Constructor can accept options for your plugin
562
- constructor(options?: { initialSelection?: TData[]; rowIdKey: keyof TData }) {
563
- // Initialize internal state based on options
564
- if (options?.initialSelection && options.rowIdKey) {
565
- options.initialSelection.forEach((item) => this.selectedRowIds.add(item[options.rowIdKey] as string | number));
566
- }
567
- }
568
-
569
- // Called by the table to provide the plugin with its API
570
- public onPluginInit = (api: IPluginAPI<TData>) => {
571
- this.api = api;
572
- };
573
-
574
- // Helper to get a unique ID for a row
575
- private getRowId = (row: TData): string | number => {
576
- // Assuming rowIdKey is passed in constructor options or via plugin API
577
- const rowIdKey = (this as any).options.rowIdKey; // Access options from constructor
578
- return row[rowIdKey] as string | number;
579
- };
580
-
581
- // Handles row clicks to toggle selection
582
- private handleRowClick = (row: TData) => {
583
- const rowId = this.getRowId(row);
584
- if (this.selectedRowIds.has(rowId)) {
585
- this.selectedRowIds.delete(rowId);
586
- } else {
587
- this.selectedRowIds.add(rowId);
588
- }
589
-
590
- // Notify the table to re-render to reflect selection changes
591
- this.api.forceUpdate();
592
-
593
- // If you need to expose the selection to the parent component,
594
- // you would typically call a callback provided via plugin options.
595
- // e.g., (this as any).options.onSelectionChange(this.getSelectedItems());
596
- };
597
-
598
- // Provides props to be spread on each table row (<tr>)
599
- public getRowProps = (row: TData): React.HTMLAttributes<HTMLTableRowElement> => {
600
- const isSelected = this.selectedRowIds.has(this.getRowId(row));
601
- return {
602
- className: isSelected ? styles.selectedRow : '', // Apply selection styling
603
- onClick: () => this.handleRowClick(row), // Attach click handler
604
- 'aria-selected': isSelected, // For accessibility
605
- };
606
- };
607
-
608
- // Optional: You can also implement renderHeader, renderFooter, processData, etc.
609
- // For example, to add a "Select All" checkbox in the header:
610
- // public renderHeader = () => {
611
- // return (
612
- // <input
613
- // type="checkbox"
614
- // checked={this.selectedRowIds.size === this.api.getData().length}
615
- // onChange={() => this.toggleSelectAll()}
616
- // />
617
- // );
618
- // };
619
- }
620
- ```
621
-
622
- **Step 2: Integrate Your Custom Plugin**
623
-
624
- Once your plugin class is defined, you can instantiate it and pass it to the `ResponsiveTable` component via the `plugins` prop.
625
-
626
- ```jsx
627
- import React from 'react';
628
- import ResponsiveTable from 'jattac.libs.web.responsive-table';
629
- import { MyCustomSelectionPlugin } from './my-custom-selection-plugin'; // Adjust path
630
-
631
- interface MyDataItem {
632
- id: string;
633
- name: string;
634
- // ... other properties
635
- }
636
-
637
- const MyTableWithCustomSelection = () => {
638
- const data: MyDataItem[] = [
639
- { id: '1', name: 'Alice' },
640
- { id: '2', name: 'Bob' },
641
- // ...
642
- ];
643
-
644
- const columns = [
645
- { displayLabel: 'ID', cellRenderer: (row: MyDataItem) => row.id },
646
- { displayLabel: 'Name', cellRenderer: (row: MyDataItem) => row.name },
647
- ];
648
-
649
- // Instantiate your custom plugin, passing any necessary options
650
- const customSelectionPlugin = new MyCustomSelectionPlugin<MyDataItem>({
651
- rowIdKey: 'id', // Crucial for identifying rows
652
- // onSelectionChange: (selectedItems) => console.log(selectedItems),
653
- });
654
-
655
- return (
656
- <ResponsiveTable
657
- columnDefinitions={columns}
658
- data={data}
659
- plugins={[customSelectionPlugin]} // Pass your custom plugin here
660
- />
661
- );
662
- };
663
-
664
- export default MyTableWithCustomSelection;
665
- ```
666
-
667
- ### Built-in Plugins
668
-
669
- #### `SortPlugin`
670
-
671
- The `SortPlugin` provides powerful, type-safe, and highly customizable column sorting. It adds intuitive UI cues, allowing users to click column headers to sort the data in ascending, descending, or original order.
672
-
673
- **Enabling the `SortPlugin`:**
674
-
675
- To use the plugin, you must first import it and provide a generic instance of it to the `plugins` prop. The real power comes from making the plugin instance generic with your data type, which provides type-safety and IDE autocompletion for the sort comparer helpers.
676
-
677
- ```jsx
678
- import React from 'react';
679
- import ResponsiveTable, { IResponsiveTableColumnDefinition, SortPlugin } from 'jattac.libs.web.responsive-table';
680
-
681
- // Define the shape of your data
682
- interface User {
683
- id: number;
684
- name: string;
685
- signupDate: string;
686
- logins: number;
687
- }
688
-
689
- // 1. Create a single, generic instance of the plugin.
690
- const sortPlugin = new SortPlugin<User>({
691
- initialSortColumn: 'user_logins', // Use the columnId
692
- initialSortDirection: 'desc',
693
- });
694
-
695
- // 2. Define the columns, using the helpers directly from the plugin instance.
696
- const columnDefinitions: IResponsiveTableColumnDefinition<User>[] = [
697
- // ... see examples below
698
- ];
699
-
700
- const UserTable = ({ users }) => (
701
- <ResponsiveTable
702
- columnDefinitions={columnDefinitions}
703
- data={users}
704
- // 3. Pass the already-configured plugin to the table.
705
- plugins={[sortPlugin]}
706
- />
707
- );
708
- ```
709
-
710
- **How to Make Columns Sortable (Opt-In):**
711
-
712
- A column is made sortable by adding a **`columnId`** and either a `sortComparer` or a `getSortableValue` property to its definition. The `columnId` must be a unique string that identifies the column.
713
-
714
- - `sortComparer`: A function that defines the exact comparison logic. This is the most powerful option and should be used for complex data types or custom logic.
715
- - `getSortableValue`: A simpler function that just returns the primitive value (string, number, etc.) to be used in a default comparison.
716
-
717
- **Example 1: Using Type-Safe Comparer Helpers**
718
-
719
- The `SortPlugin` instance provides a `comparers` object with pre-built, type-safe helper functions to eliminate boilerplate for common sorting scenarios. This is the recommended approach.
720
-
721
- ```jsx
722
- const columnDefinitions: IResponsiveTableColumnDefinition<User>[] = [
723
- {
724
- columnId: 'user_name',
725
- displayLabel: 'Name',
726
- dataKey: 'name',
727
- cellRenderer: (user) => user.name,
728
- // The plugin instance itself provides the type-safe helpers.
729
- // The string 'name' is fully type-checked against the User interface.
730
- sortComparer: sortPlugin.comparers.caseInsensitiveString('name'),
731
- },
732
- {
733
- columnId: 'user_signup_date',
734
- displayLabel: 'Signup Date',
735
- dataKey: 'signupDate',
736
- cellRenderer: (user) => new Date(user.signupDate).toLocaleDateString(),
737
- // IDE autocompletion for 'signupDate' works perfectly.
738
- sortComparer: sortPlugin.comparers.date('signupDate'),
739
- },
740
- {
741
- columnId: 'user_logins',
742
- displayLabel: 'Logins',
743
- dataKey: 'logins',
744
- cellRenderer: (user) => user.logins,
745
- sortComparer: sortPlugin.comparers.numeric('logins'),
746
- },
747
- {
748
- columnId: 'user_actions',
749
- displayLabel: 'Actions',
750
- // This column is NOT sortable because it has no sort-related properties.
751
- cellRenderer: (user) => <button>View</button>,
752
- },
753
- ];
754
- ```
755
-
756
- **Example 2: Writing a Custom `sortComparer` for a Computed Column**
757
-
758
- > **Important:** When writing a custom `sortComparer`, you **must** include all three parameters (`a`, `b`, and `direction`) in your function signature. Forgetting the `direction` parameter will cause descending sorts to fail. The IDE is configured to provide a warning if you forget, and the developer console will also show a warning at runtime.
759
-
760
- For unique requirements, you can write your own comparison function. Notice how `columnId` is used without a `dataKey`.
761
-
762
- ```jsx
763
- const columnDefinitions: IResponsiveTableColumnDefinition<User>[] = [
764
- {
765
- columnId: 'user_name_custom',
766
- displayLabel: 'Name',
767
- cellRenderer: (user) => user.name,
768
- // Writing custom logic for a case-sensitive sort
769
- sortComparer: (a, b, direction) => {
770
- const nameA = a.name; // No .toLowerCase()
771
- const nameB = b.name;
772
- if (nameA < nameB) return direction === 'asc' ? -1 : 1;
773
- if (nameA > nameB) return direction === 'asc' ? 1 : -1;
774
- return 0;
775
- },
776
- },
777
- ];
778
- ```
779
-
780
- **Example 3: Using `getSortableValue` for Simple Cases**
781
-
782
- If you don't need special logic, `getSortableValue` is a concise way to enable default sorting on a property.
783
-
784
- ```jsx
785
- const columnDefinitions: IResponsiveTableColumnDefinition<User>[] = [
786
- {
787
- columnId: 'user_logins_simple',
788
- displayLabel: 'Logins',
789
- dataKey: 'logins',
790
- cellRenderer: (user) => user.logins,
791
- // This enables a simple, default numerical sort on the 'logins' property.
792
- getSortableValue: (user) => user.logins,
793
- },
794
- ];
795
- ```
796
-
797
- **Plugin Options (via `new SortPlugin(options)`):**
798
-
799
- | Prop | Type | Description |
800
- | ---------------------- | ----------------- | -------------------------------------------------- |
801
- | `initialSortColumn` | `string` | The `columnId` of the column to sort by initially. |
802
- | `initialSortDirection` | `'asc' \| 'desc'` | The direction for the initial sort. |
803
-
804
- **`SortPlugin.comparers` API:**
805
-
806
- The `comparers` object on your `SortPlugin` instance provides the following helper methods. Each method is a factory that takes a `dataKey` (which is type-checked against your data model) and returns a `sortComparer` function.
807
-
808
- | Method | Description |
809
- | -------------------------------- | ----------------------------------------------------------------------------- |
810
- | `numeric(dataKey)` | Performs a standard numerical sort. |
811
- | `caseInsensitiveString(dataKey)` | Performs a case-insensitive alphabetical sort. |
812
- | `date(dataKey)` | Correctly sorts dates, assuming the data is a valid date string or timestamp. |
813
-
814
- #### `SelectionPlugin`
815
-
816
- The `SelectionPlugin` provides powerful and flexible row selection capabilities. It is enabled automatically by providing the `selectionProps` object to the `ResponsiveTable`. The plugin supports both single and multiple selection modes and can be used as a "controlled" or "uncontrolled" component.
817
-
818
- **Enabling the `SelectionPlugin`:**
819
-
820
- Row selection is enabled by simply passing the `selectionProps` object with an `onSelectionChange` callback.
821
-
822
- ```jsx
823
- import React, { useState } from 'react';
824
- import ResponsiveTable from 'jattac.libs.web.responsive-table';
825
-
826
- const MySelectableTable = ({ data }) => {
827
- const [selection, setSelection] = useState([]);
828
-
829
- const columns = [
830
- // ... your column definitions
831
- ];
832
-
833
- return (
834
- <ResponsiveTable
835
- columnDefinitions={columns}
836
- data={data}
837
- selectionProps={{
838
- onSelectionChange: setSelection,
839
- selectedItems: selection,
840
- rowIdKey: 'id', // A key from your data object to uniquely identify rows
841
- mode: 'multiple',
842
- }}
843
- />
844
- );
845
- };
846
- ```
847
-
848
- **Controlled vs. Uncontrolled Mode:**
849
-
850
- - **Controlled (Recommended):** By providing the `selectedItems` prop, you tell the table to operate as a controlled component. The table will always display the rows passed in this prop as selected. Your `onSelectionChange` callback is responsible for updating the state that you pass to `selectedItems`. This gives you full programmatic control over the selection.
851
- - **Uncontrolled:** If you omit the `selectedItems` prop, the table will manage its own selection state internally. This is simpler for cases where you only need to know what's selected but don't need to modify it from outside the table.
852
-
853
- **Props for `SelectionPlugin` (via `selectionProps` on `ResponsiveTable`):**
854
-
855
- | Prop | Type | Required | Description |
856
- | ---------------------- | ---------------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
857
- | `onSelectionChange` | `(selectedItems: TData[]) => void` | Yes | Callback function that receives an array of the currently selected data objects whenever the selection changes. Its presence enables the selection feature. |
858
- | `rowIdKey` | `keyof TData` | Yes | A key from your data object that provides a unique identifier for each row. This is crucial for reliably tracking selections. |
859
- | `mode` | `'single' \| 'multiple'` | No | The selection mode. Defaults to `'multiple'`. |
860
- | `selectedItems` | `TData[]` | No | If provided, the component operates in "controlled" mode. The table's selection will be a direct reflection of this prop. |
861
- | `selectedRowClassName` | `string` | No | An optional CSS class name to apply to selected rows, allowing you to override the default selection styling. |
862
-
863
- #### `FilterPlugin`
864
-
865
- > **Warning: Incompatible with Infinite Scroll**
866
- > The `FilterPlugin` is a client-side utility that only operates on data currently loaded in the browser. It is **not compatible** with the `InfiniteScrollPlugin`, as it cannot search data that has not yet been fetched from the server. For tables using infinite scroll, filtering logic must be implemented server-side by your application and passed into the `onLoadMore` function.
867
-
868
- Provides a search input to filter table data. It can be enabled by setting `filterProps.showFilter` to `true` on the `ResponsiveTable` component. For columns to be filterable, you must provide a `getFilterableValue` function in their `IResponsiveTableColumnDefinition`.
869
-
870
- **Props for `FilterPlugin` (via `filterProps` on `ResponsiveTable`):**
871
-
872
- | Prop | Type | Description |
873
- | ------------------- | --------- | --------------------------------------------------------------- |
874
- | `showFilter` | `boolean` | If `true`, displays a filter input field above the table. |
875
- | `filterPlaceholder` | `string` | Placeholder text for the filter input. Defaults to "Search...". |
876
-
877
- **Example with `FilterPlugin`:**
878
-
879
- ```jsx
880
- import React from 'react';
881
- import ResponsiveTable from 'jattac.libs.web.responsive-table';
882
-
883
- const FilterableTable = () => {
884
- const initialData = [
885
- { id: 1, name: 'Alice', email: 'alice@example.com' },
886
- { id: 2, name: 'Bob', email: 'bob@example.com' },
887
- { id: 3, name: 'Charlie', email: 'charlie@example.com' },
888
- { id: 4, name: 'David', email: 'david@example.com' },
889
- ];
890
-
891
- const columns = [
892
- { displayLabel: 'ID', cellRenderer: (row) => row.id, getFilterableValue: (row) => row.id.toString() },
893
- { displayLabel: 'Name', cellRenderer: (row) => row.name, getFilterableValue: (row) => row.name },
894
- { displayLabel: 'Email', cellRenderer: (row) => row.email, getFilterableValue: (row) => row.email },
895
- ];
896
-
897
- return (
898
- <ResponsiveTable
899
- columnDefinitions={columns}
900
- data={initialData}
901
- filterProps={{ showFilter: true, filterPlaceholder: 'Filter users...' }}
902
- />
903
- );
904
- };
905
- ```
906
-
907
- #### Infinite Scroll
908
-
909
- > **Warning: Incompatible with Client-Side Filtering**
910
- > The infinite scroll feature fetches data in chunks from a server. It is **not compatible** with the client-side `FilterPlugin`. For filtering to work correctly with infinite scroll, you must implement the filtering logic on your server and have the `onLoadMore` function fetch data that is already filtered.
911
-
912
- Enables a simple infinite scroll for loading more data as the user scrolls to the bottom of the table. This is useful for progressively loading data from an API without needing traditional pagination buttons. When enabled, the `ResponsiveTable` renders a specialized internal component optimized for this purpose.
913
-
914
- > **Important:** To enable infinite scroll, you **must** give the table a bounded height. This is done by passing the `maxHeight` prop to the `<ResponsiveTable>`. This prop creates a scrollable container for the table body, which is required for the scroll detection to work.
915
-
916
- > **Performance Note:** This implementation renders all loaded rows into the DOM to guarantee correct column alignment and simplicity. It is **not a virtualized list**. For extremely large datasets (many thousands of rows), performance may degrade as more rows are loaded. It is best suited for scenarios where loading a few hundred up to a couple thousand rows is expected.
917
-
918
- **Configuration (via `infiniteScrollProps` on `ResponsiveTable`):**
919
-
920
- | Prop | Type | Description |
921
- | ---- | ---- | ----------- |
922
-
923
- | `hasMore` | `boolean` | **Optional.** Controls the loading indicator. If omitted, the component infers this state automatically by checking if `onLoadMore` returns an empty array or `null`. If provided, your app is responsible for managing this state. |
924
- | `onLoadMore` | `(currentData: TData[]) => Promise<TData[] | null>` | A callback function that fires when the user scrolls near the end. It should fetch the next page of data and return it in a Promise. The component will stop trying to load more when this function returns `null` or an empty array. |
925
- | `loadingMoreComponent` | `ReactNode` | A custom component to display at the bottom while new data is being loaded. Defaults to a spinner animation. |
926
- | `noMoreDataComponent` | `ReactNode` | A custom component to display at the bottom when `hasMore` is `false`. Defaults to a "No more data" message. |
927
-
928
- **Comprehensive Example:**
929
-
930
- Here is a complete example showing how to use the infinite scroll feature. The parent component only needs to provide a function that fetches the next page of data.
931
-
932
- ```jsx
933
- import React, { useState, useCallback } from 'react';
934
- import ResponsiveTable from 'jattac.libs.web.responsive-table';
935
-
936
- // Define the shape of our data items
937
- interface DataItem {
938
- id: number;
939
- value: string;
940
- }
941
-
942
- // This is a mock API function to simulate fetching data.
943
- // In a real app, this would be an actual network request.
944
- const fetchData = async (page: number): Promise<DataItem[]> => {
945
- console.log(`Fetching page: ${page}`);
946
- return new Promise((resolve) => {
947
- setTimeout(() => {
948
- // Return an empty array for pages > 5 to simulate the end of the data
949
- if (page > 5) {
950
- resolve([]);
951
- return;
952
- }
953
- // Generate 20 new items for the current page
954
- const newData = Array.from({ length: 20 }, (_, i) => ({
955
- id: page * 20 + i,
956
- value: `Item #${page * 20 + i}`,
957
- }));
958
- resolve(newData);
959
- }, 500); // Simulate network latency
960
- });
961
- };
962
-
963
- const InfiniteScrollExample = () => {
964
- // Keep track of the next page to fetch.
965
- const [nextPage, setNextPage] = useState(0);
966
-
967
- // The onLoadMore function is now much simpler.
968
- // It just needs to fetch the data and return it.
969
- // The table will handle appending the data and managing the `hasMore` state internally.
970
- const loadMoreItems = useCallback(async () => {
971
- const newItems = await fetchData(nextPage);
972
- setNextPage((prevPage) => prevPage + 1);
973
- return newItems; // <-- Simply return the new items
974
- }, [nextPage]);
975
-
976
- const columns = [
977
- { displayLabel: 'ID', dataKey: 'id', cellRenderer: (row) => row.id },
978
- { displayLabel: 'Value', dataKey: 'value', cellRenderer: (row) => row.value },
979
- ];
980
-
981
- return (
982
- // The table MUST be inside a container with a defined height.
983
- <div style={{ height: '400px' }}>
984
- <ResponsiveTable
985
- columnDefinitions={columns}
986
- data={[]} // Start with an empty array of initial data
987
- maxHeight="100%"
988
- infiniteScrollProps={{
989
- onLoadMore: loadMoreItems,
990
-
991
- loadingMoreComponent: <h4>Loading more items...</h4>,
992
- noMoreDataComponent: <p>You've reached the end!</p>,
993
- }}
994
- />
995
- </div>
996
- );
997
- };
998
- ```
999
-
1000
- ---
1001
-
1002
- ## API Reference
1003
-
1004
- ### `ResponsiveTable` Props
1005
-
1006
- | Prop | Type | Required | Description |
1007
- | ----------------------------- | ------------------------------------ | -------- | ---------------------------------------------------------------------------------------------------------- |
1008
- | `columnDefinitions` | `IResponsiveTableColumnDefinition[]` | Yes | An array of objects defining the table columns. Can also accept a function for dynamic column generation. |
1009
- | `data` | `TData[]` | Yes | An array of data objects to populate the table rows. |
1010
- | `footerRows` | `IFooterRowDefinition[]` | No | An array of objects defining the table footer. |
1011
- | `onRowClick` | `(item: TData) => void` | No | A callback function that is triggered when a row is clicked. |
1012
- | `noDataComponent` | `ReactNode` | No | A custom component to display when there is no data. |
1013
- | `maxHeight` | `string` | No | Sets a maximum height for the table body, making it scrollable. |
1014
- | `mobileBreakpoint` | `number` | No | The pixel width at which the table switches to the mobile view. Defaults to `600`. |
1015
- | `enablePageLevelStickyHeader` | `boolean` | No | If `false`, disables the header from sticking to the top of the page on scroll. Defaults to `true`. |
1016
- | `plugins` | `IResponsiveTablePlugin<TData>[]` | No | An array of plugin instances to extend table functionality. |
1017
- | `selectionProps` | `object` | No | Configuration for the built-in row selection feature. See `SelectionPlugin` docs for details. |
1018
- | `infiniteScrollProps` | `object` | No | Configuration for the infinite scroll feature. When enabled, a specialized component handles data loading. |
1019
- | `filterProps` | `object` | No | Configuration for the built-in filter plugin. |
1020
- | `animationProps` | `object` | No | Configuration for animations, including `isLoading` and `animateOnLoad`. |
1021
-
1022
- ### `IResponsiveTableColumnDefinition<TData>`
1023
-
1024
- | Property | Type | Required | Description |
1025
- | -------------------- | ------------------------------------------------------------ | -------- | ---------------------------------------------------------------------------------------- |
1026
- | `displayLabel` | `ReactNode` | Yes | The label displayed in the table header (can be a string or any React component). |
1027
- | `cellRenderer` | `(row: TData) => ReactNode` | Yes | A function that returns the content to be rendered in the cell. |
1028
- | `columnId` | `string` | No | A unique string to identify the column. **Required** if the column is sortable. |
1029
- | `dataKey` | `keyof TData` | No | A key to match the column to a property in the data object. |
1030
- | `interactivity` | `object` | No | An object to define header interactivity (`onHeaderClick`, `id`, `className`). |
1031
- | `getFilterableValue` | `(row: TData) => string \| number` | No | A function that returns the string or number value to be used for filtering this column. |
1032
- | `getSortableValue` | `(row: TData) => any` | No | A function that returns a primitive value from a row to be used for default sorting. |
1033
- | `sortComparer` | `(a: TData, b: TData, direction: 'asc' \| 'desc') => number` | No | A function that provides the precise comparison logic for sorting a column. |
1034
-
1035
- ### `IFooterRowDefinition`
1036
-
1037
- | Property | Type | Required | Description |
1038
- | --------- | --------------------------- | -------- | -------------------------------------------------- |
1039
- | `columns` | `IFooterColumnDefinition[]` | Yes | An array of column definitions for the footer row. |
1040
-
1041
- ### `IFooterColumnDefinition`
1042
-
1043
- | Property | Type | Required | Description |
1044
- | -------------- | ----------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
1045
- | `colSpan` | `number` | Yes | The number of columns the footer cell should span. |
1046
- | `cellRenderer` | `() => ReactNode` | Yes | A function that returns the content for the footer cell. |
1047
- | `displayLabel` | `ReactNode` | No | An optional, explicit label for the footer cell. In mobile view, if `colSpan` is 1 and this is not provided, the corresponding column header will be used as a fallback. This is required for `colSpan` > 1 if you want a label to be displayed. |
1048
- | `onCellClick` | `() => void` | No | An optional click handler for the footer cell. |
1049
- | `className` | `string` | No | Optional class name for custom styling of the footer cell. |
1050
-
1051
- ---
1052
-
1053
- ## Breaking Changes
1054
-
1055
- ### Version 0.5.0
1056
-
1057
- **Change:** The API for `infiniteScrollProps` has been simplified.
1058
-
1059
- **Details:**
1060
- The `enableInfiniteScroll: true` property has been removed. The infinite scroll feature is now automatically enabled whenever the `infiniteScrollProps` object is provided. Additionally, the `onLoadMore` function is now a required property on `infiniteScrollProps`.
1061
-
1062
- **Reason:**
1063
- This change removes unnecessary boilerplate and makes the API more intuitive. If you provide props for infinite scrolling, it's clear you intend to use it.
1064
-
1065
- **Migration:**
1066
- To update your code, remove the `enableInfiniteScroll` property from your `infiniteScrollProps` object.
1067
-
1068
- **Before:**
1069
-
1070
- ```jsx
1071
- <ResponsiveTable
1072
- // ...
1073
- infiniteScrollProps={{
1074
- enableInfiniteScroll: true, // <-- No longer needed
1075
- onLoadMore: loadMoreItems,
1076
- }}
1077
- />
1078
- ```
1079
-
1080
- **After:**
1081
-
1082
- ```jsx
1083
- <ResponsiveTable
1084
- // ...
1085
- infiniteScrollProps={{
1086
- onLoadMore: loadMoreItems, // <-- Now required
1087
- }}
1088
- />
1089
- ```
1090
-
1091
- ---
1092
-
1093
- ## License
1094
-
1095
- This project is licensed under the MIT License.
1
+ # ResponsiveTable
2
+ ## Enterprise-Grade React Data Grid Component
3
+
4
+ ResponsiveTable is a high-performance, type-safe React component designed for complex data visualization. It provides seamless layout transitions between desktop-optimized tabular displays and mobile-optimized card views, ensuring data integrity and accessibility across all device form factors.
5
+
6
+ ## Core Capabilities
7
+ * **Dynamic Layout Orchestration:** Automated transformation between standard table structures and mobile-optimized interfaces based on configurable breakpoints.
8
+ * **Extensible Architecture:** A robust plugin system for implementing sorting, filtering, row selection, and asynchronous data fetching.
9
+ * **Intelligent Layout Scaling:** Automated recalculation of footer colSpan ranges to maintain structural alignment when columns are programmatically excluded.
10
+ * **Performance Optimized:** An atomized internal architecture that decouples state management from rendering, minimizing re-render cycles.
11
+ * **Type Safety:** Comprehensive TypeScript definitions for predictable implementation and robust development workflows.
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install jattac.libs.web.responsive-table
17
+ ```
18
+
19
+ ## Basic Implementation
20
+
21
+ The following example demonstrates a standard implementation of the ResponsiveTable component:
22
+
23
+ ```tsx
24
+ import React from 'react';
25
+ import ResponsiveTable from 'jattac.libs.web.responsive-table';
26
+
27
+ const data = [
28
+ { id: 1, name: 'Administrative User' },
29
+ { id: 2, name: 'Standard User' }
30
+ ];
31
+
32
+ const columns = [
33
+ { displayLabel: 'Identifier', cellRenderer: (row) => row.id },
34
+ { displayLabel: 'User Name', cellRenderer: (row) => row.name },
35
+ ];
36
+
37
+ const App = () => (
38
+ <ResponsiveTable
39
+ data={data}
40
+ columnDefinitions={columns}
41
+ />
42
+ );
43
+ ```
44
+
45
+ ---
46
+
47
+ ## Documentation Directory
48
+
49
+ The following technical documentation provides comprehensive implementation guidance:
50
+
51
+ 1. **[Technical Implementation Guide](./docs/examples.md)** - Practical examples for core features, including infinite scroll and plugin integration.
52
+ 2. **[Functional Capabilities](./docs/features.md)** - A high-level overview of the component's feature set.
53
+ 3. **[API Reference](./docs/api.md)** - Technical specifications for props, interfaces, and type definitions.
54
+ 4. **[Configuration Specification](./docs/configuration.md)** - Detailed guidance on performance tuning and UI customization.
55
+ 5. **[Architecture and Contribution Guide](./docs/development.md)** - Internal system design and development environment setup.
56
+
57
+ ---
58
+ **Next Step:** [Review the Technical Implementation Guide](./docs/examples.md)