3.6.1 • Published 6 months ago

david-mi-react-table v3.6.1

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

david-mi-react-table v3.6.1

Description

A react package to create a table with integrated functionalities

Functionalities

Sorting data

When clicking on a column heading, you can arrange data in 3 ways

  • Sorting in ascending order
  • Sorting in descending order
  • default (non sorted, like it was originally)

Filtering data

When writing text on the search input, only rows who have cells that includes written text will be displayed

  • Sorting state is being kept after filtering

Paginating data

A pagination system is being used to navigate through the pages and limiting amount of displayed data on the screen

  • Go to next page
  • Go to previous page
  • Go to page specified by button (if there is a lot of data, limiting amount of displayed page buttons)
  • Go to page specified in "Go to" input

Retrieving data information

A section is made on the bottom left to display informations about the data being processed

  • You can visualize the entries range of the current page (Example : Showing 41 to 50 of 500 entries)
  • You can see the number of total entries, ignoring filtering

Installation

npm i david-mi-react-table

Example

import "david-mi-react-table/style.css";
import { Table } from "david-mi-react-table";

const columns = [
  { title: "Title", accessor: "title" },
  { title: "Rating (/20)", accessor: "rating" },
];

const rows = [
  { title: "ARK: Survival Evolved", rating: 12 },
  { title: "Trials Fusion", rating: 17 },
  { title: "Counter-Strike: Source", rating: 18 },
  { title: "Dungeon Defenders", rating: 16 },
  { title: "Trials Evolution Gold Edition", rating: 18 },
  { title: "Borderlands 2", rating: 18 },
  { title: "Portal 2", rating: 19 },
  { title: "Deep Rock Galactic", rating: 15 },
  { title: "Counter-Strike 2", rating: 15 },
  { title: "Borderlands GOTY", rating: 13.5 },
  { title: "Fallout 4", rating: 16 },
  { title: "Orcs Must Die! 2", rating: 16 },
  { title: "Borderlands: The Pre-Sequel", rating: 15 },
];

function App() {
  return (
    <Table 
      columns={columns}
      rows={rows} 
     />
  );
}

Result

img

Typescript Example

You can import Row and Column types to reinforce typing They accept a generic wich are keys of a row data schema

You can avoid using Row and Column types aswell, is it not required but recommended as you will get more precise warnings

import "david-mi-react-table/style.css";
import { Table, Row, Column } from "david-mi-react-table";

interface Game {
  title: string;
  rating: number;
}

const columns: Column<keyof Game>[] = [
  { title: "Title", accessor: "title" },
  { title: "Rating (/20)", accessor: "rating" },
];

const rows: Row<keyof Game>[] = [
  { title: "ARK: Survival Evolved", rating: 12 },
  { title: "Trials Fusion", rating: 17 },
  { title: "Counter-Strike: Source", rating: 18 },
  { title: "Dungeon Defenders", rating: 16 },
  { title: "Trials Evolution Gold Edition", rating: 18 },
  { title: "Borderlands 2", rating: 18 },
  { title: "Portal 2", rating: 19 },
  { title: "Deep Rock Galactic", rating: 15 },
  { title: "Counter-Strike 2", rating: 15 },
  { title: "Borderlands GOTY", rating: 13.5 },
  { title: "Fallout 4", rating: 16 },
  { title: "Orcs Must Die! 2", rating: 16 },
  { title: "Borderlands: The Pre-Sequel", rating: 15 },
];

function App() {
  return <Table columns={columns} rows={rows} />;
}

Props

PropstypeDescriptionRequired
rowsArrayrows to display on tabletrue
columnsArraycolumns headstrue
classNamesObjectcustom class names to apply on table container and it's elementsfalse
colorsObjectcustom colors to apply on tablefalse

Column

Key nameTypeDescriptionRequired
titlestringtitle to display on column headtrue
accessorstringaccessor to target the correct cellstrue
{ 
  /* title that will be displayed at column head*/
  title: "First name",
  /* reference to a row key */
  accessor: firstName
}

Row

Key nameTypeDescriptionRequired
< key >string or numberrow valuetrue
{ 
  /* row key with it's value */
  firstName: "David"
}

classNames

KeyTypeDescriptionRequired
containerstringmain containerfalse
tableContainerstringtable wrapperfalse
tablestringtable elementfalse
pageSelectstringselect page menu on top leftfalse
searchstringsearch menu on top rightfalse
informationsstringinformations part on bottom leftfalse
navigationstringnavigation menu on bottom rightfalse
footerstringinformations and navigation menus wrapperfalse

colors

KeyTypeDescriptionRequired
hoverstringTable hover (heading, rows and buttons)false
buttonstringTable buttonsfalse
buttonCurrentPagestringTable button matching the current page numberfalse
buttonDisabledstringTable disabled buttonsfalse
sortArrowstringsorting arrows on headingfalse
sortArrowActivestringthe arrow representing the direction of current sorted column, if chosen (asc or desc. )false
headstringtable headingfalse

Types

interface Column<T> {
  title: string,
  accessor: T
}

type Row<T extends string> = {
  [key in T]: string | number
}

interface ClassNames {
  container?: string
  tableContainer?: string
  table?: string
  pageSelect?: string
  search?: string
  informations?: string
  navigation?: string
  footer?: string
}

interface Colors {
  hover?: string,
  button?: string
  buttonCurrentPage?: string
  buttonDisabled?: string
  sortArrow?: string
  sortArrowActive?: string
  head?: string
}

export interface TableProps<T extends string> {
  columns: Column<T>[],
  rows: Row<T>[]
  classNames?: ClassNames
  colors?: Colors
}

CodeSandbox demos

React : Link

React Typescript : Link

NextJs : Link

2.8.0

6 months ago

3.4.0

6 months ago

3.2.0

6 months ago

3.0.1

6 months ago

3.6.1

6 months ago

3.6.0

6 months ago

3.0.0

6 months ago

2.7.0

6 months ago

2.9.0

6 months ago

2.7.1

6 months ago

3.3.1

6 months ago

3.3.0

6 months ago

3.1.1

6 months ago

3.1.0

6 months ago

3.5.3

6 months ago

3.5.2

6 months ago

3.5.1

6 months ago

3.5.0

6 months ago

2.3.0

1 year ago

2.1.2

1 year ago

2.0.3

1 year ago

2.2.0

1 year ago

2.1.1

1 year ago

2.0.2

1 year ago

2.5.0

1 year ago

2.4.1

1 year ago

2.4.0

1 year ago

2.3.1

1 year ago

2.1.3

1 year ago

2.6.1

1 year ago

2.5.2

1 year ago

2.6.0

1 year ago

2.5.1

1 year ago

2.6.3

1 year ago

2.6.2

1 year ago

2.5.3

1 year ago

2.1.0

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

2.6.4

1 year ago

0.2.0

1 year ago

0.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago