1.0.6 • Published 7 months ago

cnc-grid v1.0.6

Weekly downloads
-
License
ISC
Repository
github
Last release
7 months ago

CNC Grid

🚧 This package is under active development. Rapid updates are being added daily, and contributions from developers are highly encouraged! 🚧

CNC Grid is a customizable and easy-to-use data grid component for React and Next.js applications. It provides flexible filtering, sorting, and pagination features, along with the ability to export data to various formats (CSV, Excel, and PDF). Built to be lightweight and highly customizable, CNC Grid fits seamlessly into your projects.

npm license downloads

Features

  • Column Visibility Management: Show or hide columns based on user preferences.
  • Filtering and Sorting: Easily filter and sort data on multiple columns.
  • Pagination: Built-in pagination with configurable page sizes.
  • Data Export: Export data to CSV, Excel, and PDF formats.
  • Customizable: Customize styles, column headers, and more.
  • Responsive: Adjusts to screen sizes and supports fixed headers.

Demo and Documentation

Visit the homepage for a live demo and complete documentation.

Installation

To install CNC Grid in your project, use npm:

npm install cnc-grid

Usage

Here is a quick example of how to use CNC Grid in your project:

import React from 'react';
import CNCGrid from 'cnc-grid';

const columns = [
  { headerName: 'Brand', field: 'brand', sortable: true, filterable: true },
  { headerName: 'Product', field: 'product', sortable: true, filterable: true },
  { headerName: 'Price', field: 'price', sortable: true, filterable: false },
];

const data = [
  { brand: 'Apple', product: 'iPhone 12', price: 799 },
  { brand: 'Samsung', product: 'Galaxy S21', price: 699 },
  { brand: 'Google', product: 'Pixel 5', price: 699 },
];

const App = () => (
  <CNCGrid
    colDef={columns}
    rowData={data}
    gridHeight="500px"
    gridWidth="100%"
    export={{ csv: true, excel: true, pdf: true }}
    pagination
  />
);

export default App;

Props

CNCGrid Props

PropTypeDescriptionDefault
colDefArray<ColumnDef>Defines columns of the grid. Each object in the array represents a column with its settings.Required
rowDataArray<Object>Array of data objects representing rows in the grid.Required
gridHeightstringSets the height of the grid."500px"
gridWidthstringSets the width of the grid."100%"
rowHeightnumberHeight of each row in the grid.40
headerHeightnumberHeight of the header row.50
export{ csv?: boolean, excel?: boolean, pdf?: boolean }Enables export options for CSV, Excel, and PDF.{ csv: false, excel: false, pdf: false }
paginationbooleanEnables or disables pagination for the grid.false
pageSizenumberNumber of rows per page if pagination is enabled.10
pageSizesArray<number>Array of page size options for pagination.[10, 20, 50]
currentPagenumberThe current active page if pagination is enabled.1
onSelectionChange(selectedRows: any) => voidCallback function called when row selection changes.undefined
onRowClick(row: any) => voidCallback function called when a row is clicked.undefined
onRowDoubleClick(row: any) => voidCallback function called when a row is double-clicked.undefined
onRowRightClick(row: any) => voidCallback function called when a row is right-clicked.undefined
onCellClick(cell: any) => voidCallback function called when a cell is clicked.undefined
onCellDoubleClick(cell: any) => voidCallback function called when a cell is double-clicked.undefined
onCellRightClick(cell: any) => voidCallback function called when a cell is right-clicked.undefined
onSortChange(sortField: string, sortDirection: 'asc' | 'desc') => voidCallback function called when sorting changes.undefined
onFilterChange(filterText: string) => voidCallback function called when a filter is applied.undefined
onColumnResize(field: string, width: number) => voidCallback function called when a column is resized.undefined
onColumnVisibilityChange(field: string, visible: boolean) => voidCallback for column visibility toggle.undefined
onColumnOrderChange(field: string, order: number) => voidCallback for changing column order.undefined
onGridReady(api: any) => voidCallback function called when the grid is initialized.undefined
loadingbooleanShows a loading indicator overlay on the grid if set to true.false
noDataMessagestringMessage to display when there is no data in the grid."No data available"

ColumnDef Props

PropTypeDescriptionDefault
headerNamestringThe name of the column displayed in the header.Required
fieldstringThe field name in rowData for this column.Required
sortablebooleanEnables sorting for the column.false
filterablebooleanEnables filtering for the column.false
widthnumberSets the width of the column.undefined
visiblebooleanControls column visibility.true

Exports

Export Options

You can export data from the grid in various formats. By setting the export prop, you can enable or disable export buttons for CSV, Excel, and PDF formats.

export: {
  csv: true,
  excel: true,
  pdf: true
}

Contributing

Contributions are welcome! Please follow the contribution guidelines.

License

This project is licensed under the ISC License. See the LICENSE file for more information.

Author

Developed by Syed Suhaib Zia from Code N Code IT Solutions.

Links