1.0.16 • Published 4 months ago

easyv2-table v1.0.16

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

easyv2-table

npm version License: MIT

A lightweight and customizable React table component with:

  • Sorting (ASC, DESC, and 3rd click to remove sort)
  • Pagination (+ “Show X entries”)
  • Search (optionally filters rows, using startsWith)
  • “Showing X to X of X entries” display

🛠 Installation

npm install easyv2-table

📌 Quick Start

🔹 Minimal Example

import { EasyTableV2, ColumnDef } from "easyv2-table";

type Person = {
  id: string;
  firstName: string;
  lastName: string;
};

const data: Person[] = [
  { id: "1", firstName: "Alice", lastName: "Smith" },
  { id: "2", firstName: "Bob", lastName: "Johnson" },
];

const columns: ColumnDef<Person>[] = [
  { key: "firstName", label: "First Name" },
  { key: "lastName", label: "Last Name" },
];

const App = () => {
  return <EasyTableV2 data={data} columns={columns} />;
};

export default App;

💡 By default, EasyTableV2 doesn't enable pagination or search. It simply displays your data in a table.


📌 Enabling Features

🔹 Pagination

  • pagination (boolean): toggles pagination on/off.
  • itemsPerPage (number): initial page size (defaults to 10).
  • A select drop-down “Show X entries” will appear, letting users choose 10,25,50,100 entries.

💡 The component shows numeric pagination with ellipses if there are many pages. For example, if you’re on page 5 out of 12, it displays 1 … 4 5 6 … 12. »

🔹 Search

💡 search (boolean): enables a search bar that filters rows by startsWith on any column.

🔹 Sorting

  • Sorting is enabled by default on all columns.
  • Click on a column header → ASC → DESC → 3rd click → removes sort.
  • If you don’t want sorting, pass columns without sortable or remove the logic from the code if you prefer.

🎯 Prop Reference

PropTypeDefaultDescription
dataT[][]The dataset to be displayed
columnsColumnDef[][]Column definitions*
paginationbooleanfalseEnables/disables pagination
itemsPerPagenumber10Initial number of items per page
searchbooleanfalseEnables/disables the built-in search bar

*Each ColumnDef<T> can optionally have a render function to customize the cell content.


🔹 Where:

export interface ColumnDef { key: keyof T; label: string; render?: (value: Tkeyof T, row: T) => React.ReactNode; }

🔹 Render Exemple :

const columns: ColumnDef<User>[] = [
  { key: "firstName", label: "First Name" },
  { key: "age", label: "Age" },
  {
    key: "dateOfBirth",
    label: "Date of Birth",
    // Render a custom date
    render: (value) => {
      if (!value) return "";
      const date = new Date(value as string);
      return date.toLocaleDateString();
    },
  },
];

🎨 Custom Styles

easyv2-table comes with built-in styles. You don’t need to import a separate CSS file. If you want to override the default appearance, simply add your own custom CSS rules or inline styles targeting .easyv2-... class names.


🔥 Advanced Usage

  • Edit your data in real-time, pass new props, and EasyTableV2 will update automatically.
  • Three-click sort: 1st = ascending, 2nd = descending, 3rd = remove sort.
  • Filtering with search uses startsWith, case-insensitive.
  • Pagination handles the data after filtering and sorting, so all steps are chained logically.

📜 License

MIT © 2025 Maxb06 - Maxime Brunet

1.0.16

4 months ago

1.0.15

4 months ago

1.0.14

4 months ago

1.0.13

4 months ago

1.0.12

4 months ago

1.0.11

4 months ago

1.0.10

4 months ago

1.0.9

4 months ago

1.0.8

5 months ago

1.0.7

5 months ago

1.0.6

5 months ago

1.0.5

5 months ago

1.0.4

5 months ago

1.0.3

5 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago