1.0.11 • Published 6 months ago

blkbox-data-grid-test v1.0.11

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

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 NameTypeDefault ValueDescription
columnsColumn[]-Defines the table's column structure, including field, header, width, etc.
rowsRow[][]Array of row objects. Supports nested children for expandable rows.
enableColumnDragbooleanfalseEnables dragging and reordering of columns.
enableRowDragbooleanfalseEnables dragging and reordering of rows.
allowRowExpansionbooleanfalseAllows rows to be expandable to show nested content.
loadingbooleanfalseDisplays loading skeletons while data is being fetched.
showPaginatorbooleanfalseToggles pagination controls for the table.
rowsPerPagenumber5Number of rows to display per page.
paginatorOptionsnumber[][5, 10, 15]Options for rows per page in the pagination dropdown.
onRowExpanded(data) => void-Callback triggered when a row is expanded.
customEmptyStateReactNode"No Data"Custom empty state component when there are no rows.
customSettingsCustomSettings{}Additional custom settings for the table.
primaryKeystring'asset_id'Unique key for identifying rows.
gridMainContainerClassstring-Custom CSS class for the main grid container.
searchTextstring""Text to filter rows based on column values.
tableRefMutableRefObject-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:

  1. Fork the repository.
  2. Create a feature branch: git checkout -b my-feature
  3. Commit your changes: git commit -m 'Add new feature'
  4. Push to the branch: git push origin my-feature
  5. Open a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

1.0.11

6 months ago

1.0.10

6 months ago

1.0.9

6 months ago

1.0.8

6 months ago

1.0.7

6 months ago

1.0.6

6 months ago

1.0.5

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago