blkbox-data-grid-test v1.0.11
BlkBoxTable
BlkBoxTable is a flexible and feature-rich React table component built to handle large datasets with high performance. This component offers features like row selection, column and row dragging, pagination, sticky columns, and advanced filtering with search functionality. It's designed for a seamless and customizable table experience.
This library is maintained and supported by BlkBox, ensuring regular updates and improvements.
Features
- Sticky Columns: Keep important columns visible during horizontal scrolling.
- Expandable Rows: Show additional details for rows with nested content.
- Virtualized Rows: Efficient rendering for large datasets by only displaying visible rows.
- Column and Row Dragging: Reorder columns and rows interactively.
- Row Selection: Select rows individually or in bulk.
- Pagination: Simplify navigation with paginated views.
- Search Functionality: Filter rows based on a search query.
- Customizable Settings: Adjust row counts, appearance, and behaviors.
- Loading State: Built-in loading placeholders for smooth data fetching.
Installation
Install the package using npm or yarn:
npm install blkbox-data-grid
or
yarn add blkbox-data-grid
Basic Usage
Here is an example to get started:
import React, { useRef } from 'react';
import BlkBoxTable from 'blkbox-data-grid';
const columns = [
{ field: 'id', headerName: 'ID', width: 100 },
{ field: 'name', headerName: 'Name', sorting: true },
{ field: 'age', headerName: 'Age', sorting: true },
];
const rows = [
{ id: 1, name: 'John Doe', age: 30 },
{ id: 2, name: 'Jane Doe', age: 25 },
];
const App = () => {
const tableRef = useRef(null);
const handleRowExpanded = (data) => {
console.log('Row expanded:', data);
};
return (
<BlkBoxTable
tableRef={tableRef}
columns={columns}
rows={rows}
enableColumnDrag={true}
allowRowExpansion={true}
showPaginator={true}
searchText="John"
loading={false}
rowsPerPage={5}
paginatorOptions={[5, 10, 15]}
onRowExpanded={handleRowExpanded}
/>
);
};
export default App;
Props
Prop Name | Type | Default Value | Description |
---|---|---|---|
columns | Column[] | - | Defines the table's column structure, including field, header, width, etc. |
rows | Row[] | [] | Array of row objects. Supports nested children for expandable rows. |
enableColumnDrag | boolean | false | Enables dragging and reordering of columns. |
enableRowDrag | boolean | false | Enables dragging and reordering of rows. |
allowRowExpansion | boolean | false | Allows rows to be expandable to show nested content. |
loading | boolean | false | Displays loading skeletons while data is being fetched. |
showPaginator | boolean | false | Toggles pagination controls for the table. |
rowsPerPage | number | 5 | Number of rows to display per page. |
paginatorOptions | number[] | [5, 10, 15] | Options for rows per page in the pagination dropdown. |
onRowExpanded | (data) => void | - | Callback triggered when a row is expanded. |
customEmptyState | ReactNode | "No Data" | Custom empty state component when there are no rows. |
customSettings | CustomSettings | {} | Additional custom settings for the table. |
primaryKey | string | 'asset_id' | Unique key for identifying rows. |
gridMainContainerClass | string | - | Custom CSS class for the main grid container. |
searchText | string | "" | Text to filter rows based on column values. |
tableRef | MutableRefObject | - | Ref object to expose table methods to the parent. |
Column Type
The columns
prop is an array of objects with the following structure:
type Column = {
field: string; // Unique identifier for the column
headerName: string; // Display name for the column header
width?: number; // Optional width of the column
sorting?: boolean; // Whether sorting is enabled for this column
sticky?: 'left' | 'right'; // Optional sticky positioning
alignItem?: 'left' | 'center' | 'right'; // Alignment of content
body?: (row: any, field: string, level: number) => React.ReactNode; // Custom renderer for the cell
showExpansionIcon?: boolean; // Show expansion icon for expandable rows
};
Row Type
The rows
prop is an array of objects with the following structure:
type Row = {
id?: string; // Unique identifier for the row
[key: string]: any; // Additional fields corresponding to column keys
children?: Row[]; // Nested rows for expandable rows
};
CustomSettings Type
The customSettings
prop can be used to pass additional configuration for customizing table behaviors. Here's the structure:
type CustomSettings = {
itemHeight?: number; // Height of each row in pixels
amount?: number; // Number of rows to render in a single batch
tolerance?: number; // Buffer of rows to render beyond the viewport
minIndex?: number; // Minimum index for virtualized rows
maxIndex?: number; // Maximum index for virtualized rows
startIndex?: number; // Starting index for rendering rows
initialPosition?: number; // Initial scroll position
};
Advanced Features
Row Selection
Enable row selection for better interactivity:
<BlkBoxTable
columns={columns}
rows={rows}
allowRowSelection={true}
primaryKey="id"
/>
Column Dragging
Reorder columns easily:
<BlkBoxTable
columns={columns}
rows={rows}
enableColumnDrag={true}
/>
Row Expansion
Expand rows to display additional details:
<BlkBoxTable
columns={columns}
rows={rows}
allowRowExpansion={true}
onRowExpanded={(row) => console.log('Expanded row:', row)}
/>
Search Functionality
Filter rows based on a search query:
<BlkBoxTable
columns={columns}
rows={rows}
searchText="Jane"
/>
Customization
Styling
Override default styles using the gridMainContainerClass
prop or by modifying the accompanying CSS files.
Custom Empty State
Provide a custom empty state component:
<BlkBoxTable
columns={columns}
rows={[]}
customEmptyState={<div>No Records Found</div>}
/>
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a feature branch:
git checkout -b my-feature
- Commit your changes:
git commit -m 'Add new feature'
- Push to the branch:
git push origin my-feature
- Open a pull request.
License
This project is licensed under the MIT License. See the LICENSE
file for details.