simple-table-helper
v1.0.5
Published
A versatile React custom hook for seamlessly integrating DataTable functionality into your applications.
Downloads
4
Readme
simple-table-helper
A custom hook for managing a DataTable instance in React applications.
Installation
You can install the package via npm or yarn:
npm install simple-table-helper
or
yarn add simple-table-helper
Before using this hook, ensure that you have installed the required dependencies:
- datatables.net
- react
npm install datatables.net react
Usage
import React from "react";
import { useDataTable } from "simple-table-helper";
const MyComponent = () => {
const tableRef = useDataTable({
initialSort: [[0, "asc"]], // Initial sorting configuration
defaultPageLength: 25, // Default number of items per page
columns: [
{ title: "Name", data: "name" },
{ title: "Age", data: "age" },
// Add more column configurations as needed
],
data: [
{ name: "John", age: 30 },
{ name: "Jane", age: 25 },
// Add more data rows as needed
],
});
return (
<div>
<h1>My DataTable</h1>
<table ref={tableRef}></table>
</div>
);
};
export default MyComponent;