Skip to content

Commit cb659ac

Browse files
feat: Add filter, search and added few style updates
1 parent f282279 commit cb659ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+12363
-14414
lines changed

README.md

Lines changed: 222 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,23 @@ const columns = [
8282
key: 'name',
8383
title: 'Name',
8484
filterable: true,
85+
sortable: true,
86+
width: '25%',
8587
},
8688
{
8789
key: 'value',
8890
title: 'Value',
8991
filterable: true,
92+
sortable: true,
93+
width: '20%',
9094
render: (value) => `$${value}`,
9195
},
9296
{
9397
key: 'status',
9498
title: 'Status',
9599
filterable: true,
100+
sortable: true,
101+
width: '15%',
96102
render: (value) => (
97103
<span style={{
98104
padding: '4px 8px',
@@ -136,6 +142,13 @@ The MultiLevelTable component accepts the following props:
136142
| expandIcon | ReactNode | No | - | Custom icon for expanding rows |
137143
| selectable | boolean | No | false | Enable/disable row selection |
138144
| onSelectionChange | function | No | - | Callback function when selection changes |
145+
| onRowClick | function | No | - | Callback function when a parent row is clicked |
146+
| onDelete | function | No | - | Callback function for row deletion |
147+
| searchable | boolean | No | true | Enable/disable global search functionality |
148+
| filterable | boolean | No | true | Enable/disable column filtering |
149+
| exportable | boolean | No | false | Enable/disable data export functionality |
150+
| exportFormats | array | No | ['csv', 'excel'] | Available export formats |
151+
| onExport | function | No | - | Custom export handler function |
139152

140153
## 3. Customization
141154

@@ -151,6 +164,12 @@ Each column object should have the following properties:
151164
| filterable | boolean | No | Whether the column can be filtered |
152165
| sortable | boolean | No | Whether the column can be sorted |
153166
| customSortFn | function | No | Custom sorting function. Receives (rowA: DataItem, rowB: DataItem, columnId: string) as parameters |
167+
| width | string | No | Column width (e.g., '150px', '20%') |
168+
| minWidth | string | No | Minimum column width |
169+
| maxWidth | string | No | Maximum column width |
170+
| align | string | No | Text alignment ('left', 'center', 'right') |
171+
| className | string | No | Custom CSS class for the column |
172+
| style | object | No | Custom inline styles for the column |
154173

155174
### 3.2 Expand Icon Customization
156175

@@ -186,6 +205,8 @@ The table supports row selection with the following props:
186205
| selectable | boolean | Enable/disable row selection functionality |
187206
| onSelectionChange | function | Callback function that receives a Set of selected row IDs |
188207

208+
**Note**: Child rows (nested rows) do not display checkboxes. They automatically show placeholder spacers to maintain alignment with parent rows.
209+
189210
### 3.4 Sort Icons
190211

191212
You can customize the sort icons for ascending and descending states:
@@ -205,7 +226,86 @@ You can customize the sort icons for ascending and descending states:
205226
| ascendingIcon | ReactNode | Custom icon component for ascending sort state |
206227
| descendingIcon | ReactNode | Custom icon component for descending sort state |
207228

208-
### 3.5 Pagination
229+
### 3.5 Search and Filter Features
230+
231+
The table provides comprehensive search and filtering capabilities:
232+
233+
#### Global Search
234+
- **Searchable**: Enable/disable global search across all columns
235+
- **Search Input**: Real-time search with debounced input
236+
- **Search Icon**: Customizable search icon with proper positioning
237+
- **Placeholder Text**: Customizable placeholder text for search input
238+
239+
#### Column Filtering
240+
- **Filterable Columns**: Individual columns can be marked as filterable
241+
- **Filter Dropdowns**: Dropdown-based filtering with multiple selection
242+
- **Filter Options**: Custom filter options for each column
243+
- **Filter State**: Maintains filter state across pagination
244+
245+
**Important Note**: Search and filter features are currently implemented at the parent level only. Child rows (nested rows) are not included in search results or filter operations. This ensures consistent behavior and performance.
246+
247+
#### Filter Configuration
248+
```tsx
249+
const columns = [
250+
{
251+
key: 'status',
252+
title: 'Status',
253+
filterable: true,
254+
filterOptions: [
255+
{ label: 'Active', value: 'active' },
256+
{ label: 'Pending', value: 'pending' },
257+
{ label: 'Completed', value: 'completed' }
258+
]
259+
}
260+
];
261+
```
262+
263+
### 3.6 Export Functionality
264+
265+
The table supports data export with customizable options:
266+
267+
| Prop | Type | Description |
268+
|------|------|-------------|
269+
| exportable | boolean | Enable/disable export functionality |
270+
| exportFormats | array | Available export formats (csv, excel, json) |
271+
| onExport | function | Custom export handler function |
272+
273+
```tsx
274+
<MultiLevelTable
275+
data={data}
276+
columns={columns}
277+
exportable={true}
278+
exportFormats={['csv', 'excel']}
279+
onExport={(data, format) => {
280+
// Custom export logic
281+
console.log('Exporting:', data, format);
282+
}}
283+
/>
284+
```
285+
286+
### 3.7 Row Actions
287+
288+
The table supports row-level actions:
289+
290+
| Prop | Type | Description |
291+
|------|------|-------------|
292+
| onRowClick | function | Callback when parent row is clicked |
293+
| onDelete | function | Callback for row deletion with confirmation |
294+
295+
```tsx
296+
<MultiLevelTable
297+
data={data}
298+
columns={columns}
299+
onRowClick={(row) => {
300+
console.log('Row clicked:', row);
301+
}}
302+
onDelete={(rowId, rowName) => {
303+
console.log('Delete row:', rowId, rowName);
304+
}}
305+
/>
306+
```
307+
308+
### 3.8 Pagination
209309

210310
The table component provides comprehensive pagination functionality. You can either use the default pagination or create a custom one using the pagination props:
211311

@@ -274,9 +374,9 @@ const CustomPagination = ({
274374
/>
275375
```
276376

277-
### 3.6 Theme Customization
377+
### 3.9 Theme Customization
278378

279-
The table component supports theme customization through the `theme` prop. Here's the complete theme interface:
379+
The table component supports comprehensive theme customization through the `theme` prop. Here's the complete theme interface:
280380

281381
```tsx
282382
interface ThemeProps {
@@ -394,18 +494,78 @@ const theme = {
394494
```
395495

396496
The theme customization allows you to:
397-
- Customize global colors for the table
398-
- Style table components (header, cells, rows)
399-
- Configure nested level appearances
400-
- Customize filter and pagination components
401-
- Style the expand icon
402-
403-
## 4. Development
497+
- **Global Colors**: Customize background, primary, text, and border colors
498+
- **Table Components**: Style headers, cells, and rows with custom colors and borders
499+
- **Nested Levels**: Configure different background colors for each nesting level
500+
- **Filter Components**: Customize filter dropdowns, inputs, and focus states
501+
- **Pagination**: Style pagination buttons, selects, and info text
502+
- **Icons**: Customize expand, sort, and action icon colors
503+
- **Responsive Design**: All theme properties support responsive breakpoints
504+
- **CSS Variables**: Theme properties can use CSS custom properties for dynamic theming
505+
506+
## 4. Component Features and Customization
507+
508+
### 4.1 MultiLevelTable Component
509+
- **Hierarchical Data**: Supports unlimited nesting levels with automatic indentation
510+
- **Responsive Design**: Percentage-based column widths with fixed table layout
511+
- **Performance Optimized**: Virtual scrolling support for large datasets
512+
- **Accessibility**: ARIA labels, keyboard navigation, and screen reader support
513+
- **Customizable Icons**: Replace default expand, sort, and action icons
514+
- **Event Handling**: Comprehensive callback system for all user interactions
515+
516+
### 4.2 TableRow Component
517+
- **Level-based Styling**: Different background colors for each nesting level
518+
- **Expand/Collapse**: Smooth animations for row expansion and collapse
519+
- **Selection State**: Visual feedback for selected rows
520+
- **Click Handlers**: Support for row click and action button clicks
521+
- **Custom Rendering**: Flexible cell content rendering with custom components
522+
523+
### 4.3 TableCell Component
524+
- **Flexible Content**: Support for text, numbers, custom components, and HTML
525+
- **Alignment Options**: Left, center, and right text alignment
526+
- **Custom Styling**: Inline styles and CSS classes for individual cells
527+
- **Icon Integration**: Built-in support for expand, sort, and action icons
528+
- **Responsive Behavior**: Automatic text truncation and ellipsis
529+
530+
### 4.4 TableHeader Component
531+
- **Sortable Columns**: Click-to-sort functionality with custom sort icons
532+
- **Filter Integration**: Dropdown filters with multi-select capability
533+
- **Custom Styling**: Theme-based header styling with hover effects
534+
- **Accessibility**: Proper ARIA labels and keyboard navigation
535+
- **Responsive Design**: Adaptive header layout for mobile devices
536+
537+
### 4.5 Pagination Component
538+
- **Page Navigation**: Previous/next buttons with page number display
539+
- **Page Size Selection**: Dropdown to change items per page
540+
- **Custom Rendering**: Complete pagination component replacement
541+
- **State Management**: Automatic page state handling
542+
- **Responsive Layout**: Mobile-friendly pagination controls
543+
544+
### 4.6 Filter Components
545+
- **Dropdown Filters**: Multi-select dropdown with search capability
546+
- **Global Search**: Real-time search across all columns
547+
- **Filter State**: Persistent filter state across pagination
548+
- **Custom Options**: Configurable filter options per column
549+
- **Outside Click**: Automatic dropdown closure on outside clicks
550+
551+
### 4.7 Export Components
552+
- **Multiple Formats**: CSV, Excel, and JSON export support
553+
- **Custom Handlers**: Flexible export function customization
554+
- **Data Filtering**: Export only visible or selected data
555+
- **Progress Feedback**: Export progress indicators
556+
- **Error Handling**: Comprehensive error handling for export operations
557+
558+
## 5. Development
404559

405560
### 4.1 Project Structure
406561
- `src/App.tsx` - A demo component that showcases the MultiLevelTable with sample data
407562
- `src/main.tsx` - The entry point for the development environment
408563
- `src/index.css` - Basic styling for the table component
564+
- `src/components/` - All table components (MultiLevelTable, TableRow, TableCell, etc.)
565+
- `src/styles/` - CSS files for styling individual components
566+
- `src/types/` - TypeScript type definitions
567+
- `src/constants/` - Theme and configuration constants
568+
- `example/` - Complete example application with all features
409569

410570
### 4.2 Development Commands
411571
```bash
@@ -420,15 +580,18 @@ npm run lint
420580
```
421581

422582
### 4.3 Development Features
423-
- Hot Module Replacement (HMR) for instant feedback
424-
- TypeScript support with type checking
425-
- ESLint configuration for code quality
426-
- Sample data and configurations for testing
427-
- Basic styling for quick visualization
583+
- **Hot Module Replacement (HMR)**: Instant feedback during development
584+
- **TypeScript Support**: Full type checking and IntelliSense support
585+
- **ESLint Configuration**: Code quality and consistency enforcement
586+
- **Sample Data**: Comprehensive test data with nested structures
587+
- **Component Testing**: Unit tests for all major components
588+
- **Responsive Design**: Mobile-first responsive design patterns
589+
- **Accessibility**: ARIA labels and keyboard navigation support
590+
- **Performance**: Optimized rendering with React.memo and useMemo
428591

429-
## 5. Example
592+
## 6. Example
430593

431-
Here's a complete example showing how to use the component with custom styling and rendering:
594+
Here's a complete example showing how to use the component with all features enabled:
432595

433596
```tsx
434597
import React from 'react';
@@ -489,12 +652,54 @@ function App() {
489652
},
490653
];
491654

655+
const theme = {
656+
colors: {
657+
background: '#ffffff',
658+
primaryColor: '#1976d2',
659+
textColor: '#333333',
660+
borderColor: '#e0e0e0'
661+
},
662+
table: {
663+
header: {
664+
background: '#f5f5f5',
665+
textColor: '#333333',
666+
borderColor: '#e0e0e0'
667+
},
668+
cell: {
669+
textColor: '#333333',
670+
borderColor: '#e0e0e0'
671+
},
672+
row: {
673+
levelColors: [
674+
{ background: '#ffffff' },
675+
{ background: '#f8f8f8' },
676+
{ background: '#f5f5f5' }
677+
]
678+
}
679+
}
680+
};
681+
492682
return (
493683
<div>
494684
<MultiLevelTable
495685
data={data}
496686
columns={columns}
497687
pageSize={10}
688+
theme={theme}
689+
sortable={true}
690+
selectable={true}
691+
searchable={true}
692+
filterable={true}
693+
exportable={true}
694+
onSelectionChange={(selectedRows) => {
695+
console.log('Selected rows:', selectedRows);
696+
}}
697+
onRowClick={(row) => {
698+
console.log('Row clicked:', row);
699+
}}
700+
onDelete={(rowId, rowName) => {
701+
console.log('Delete row:', rowId, rowName);
702+
}}
498703
/>
499704
</div>
500705
);

example/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ This is an example project demonstrating the usage of `@keyvaluesystems/multilev
1111
- Filtering
1212
- Pagination
1313
- Theme customization
14+
- Export functionality (CSV)
15+
- Generic Button components
16+
- Action button groups with dropdowns
1417

1518
## Getting Started
1619

@@ -56,6 +59,23 @@ The example demonstrates:
5659
- Sorting
5760
- Filtering
5861
- Pagination
62+
- CSV Export with dropdown
63+
- Action buttons with badges
64+
- Delete functionality with confirmation popup
65+
66+
5. **Button Components**
67+
- Generic Button component with icon and text
68+
- ButtonGroup for managing multiple action buttons
69+
- Support for badges, dropdowns, and custom icons
70+
- Theme-aware styling
71+
- Flexible icon positioning (left or right of text)
72+
73+
6. **Popup Component**
74+
- Generic confirmation popup
75+
- Customizable icon, title, text, and buttons
76+
- Theme-aware styling
77+
- Accessibility features (ESC key, click outside)
78+
- Responsive design
5979

6080
## Learn More
6181

0 commit comments

Comments
 (0)