2.0.0 • Published 12 months ago

jenish-data-table v2.0.0

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

DataTable Component

A reusable, customizable data table component built using Material-UI, designed to support sorting, pagination, and search functionality.

Installation

To install the component, run:

npm i jenish-data-table

usage

import React, { useState } from "react";
import DataTable from "your-package-name";

const App = () => {
  const [page, setPage] = useState(0);
  const [rowsPerPage, setRowsPerPage] = useState(5);
  const [searchValue, setSearchValue] = useState("");

  const headCols = [
    {
      id: "name",
      name: "Name",
      sorting: true,
      sortingName: "name",
      order: "asc",
      width: "25%",
    },
    {
      id: "age",
      name: "Age",
      sorting: true,
      sortingName: "age",
      order: "desc",
      width: "25%",
    },
    { id: "address", name: "Address", width: "50%" },
  ];

  const rows = [
    ["John Doe", "30", "1234 Elm Street"],
    ["Jane Doe", "25", "5678 Oak Street"],
  ];

  const totalRecords = 100;

  const handleChangePage = (event, newPage) => {
    setPage(newPage - 1);
  };

  const handleChangeRowsPerPage = (event) => {
    setRowsPerPage(parseInt(event.target.value, 10));
  };

  const handleSearch = (event) => {
    setSearchValue(event.target.value);
    // Add search functionality here
  };

  const handleSortBy = (colName) => {
    // Handle sort logic here
  };

  const handleOrder = (order) => {
    // Handle order change here
  };

  return (
    <DataTable
      headCols={headCols}
      rows={rows}
      page={page}
      rowsPerPage={rowsPerPage}
      totalRecords={totalRecords}
      handleChangePage={handleChangePage}
      handleChangeRowsPerPage={handleChangeRowsPerPage}
      searchRecord={handleSearch}
      searchValue={searchValue}
      changeSortBy={handleSortBy}
      changeOrder={handleOrder}
      isLoading={false}
      searchPlaceholder="Search records..."
    />
  );
};

export default App;

Props

Prop NameTypeDefault ValueDescription
headColsarray[]Array of column headers. Each column should have id, name, sorting, and width.
rowsarray[]Array of rows. Each row is an array of column values.
pagenumber0Current page number.
rowsPerPagenumber5Number of rows displayed per page.
totalRecordsnumber0Total number of records in the dataset.
handleChangePagefunction() => {}Callback to handle page change.
handleChangeRowsPerPagefunction() => {}Callback to handle rows per page change.
searchBarPositionstring"center"Position of the search bar (e.g., "center", "left", "right").
searchRecordfunction() => {}Callback function for handling search.
rowsPerPageOptionsarray[5, 10, 25]Array of rows per page options.
datatablebooleantrueIf true, renders the table with search, pagination, and sorting functionality.
searchValuestring""Value of the search input.
changeSortByfunction() => {}Callback for handling sorting by column.
changeOrderfunction() => {}Callback for changing the sorting order (asc or desc).
isLoadingbooleanfalseIf true, displays a loading spinner.
searchPlaceholderstring""Placeholder text for the search input.

Features

  • Sorting: Allows sorting of columns by ascending or descending order.
  • Pagination: Supports pagination with customizable rows per page.
  • Search: Includes a search bar to filter rows.
  • Loading State: Displays a loading spinner when data is being fetched.
2.0.0

12 months ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago