1.0.2 • Published 1 year ago

react-plugin-table v1.0.2

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
1 year ago

react-plugin-table

A react plugin for implementing data tables

NPM downloads NPM version Package size

NPM Storybook

Installation

npm install react-plugin-table

Usage

import { Table } from 'react-plugin-table';

Next, declare the columns your table will need in an array of objects :

  const columns = [
  {
    label: 'First column',
    cell: 'firstColumn',
    isSortable: true,
  },
  {
    label: 'Second column',
    cell: 'secondColumn'
  },
  {
    label: 'Third column',
    cell: 'thirdColumn'
  }
];

Declare the contents of your table with an array containing an object corresponding to each row. If you don't want any cells to appear, simply don't declare the column.

Warning: a unique id must be declared in each object

An example of data :

  const rows = [
  {
    id: '1',
    firstColumn: 'First Line',
    secondColumn: 'First Line',
    thirdColumn: 'First Line',
  },
  {
    id: '2',
    firstColumn: 'Second Line',
    secondColumn: 'Second Line',
    thirdColumn: 'Second Line',
  },
  {
    id: '3',
    firstColumn: 'Third Line',
    secondColumn: 'Third Line',
    thirdColumn: 'Third Line',
  },
];

To finish, use the table as follows:

  return (
  <Table columns={columns} label="Table label" description="Table description" rows={rows}/>
);

Features

  • Column sorting : The columns having the sortable boolean to true will have the sort option active, which allows them to be ascendingly sorted on the first click on the header of the column, and descendingly sorted on second click of the column.
  • Search : A table with isFiltered boolean with true value, a search input will be displayed.
  • Pagination : A pagination system is implemented to present tables with many entries in a simple way. You can select the amount of data to be displayed per page using a selector.
  • Responsive : The component is responsive and can be displayed on desktops and small screens without scrolling.

Future developments

Essential

  • Make the colours used in css customisable
  • Finish implementing accessible elements (aria attributes and keyboard navigation management)
  • Be able to add action buttons to a list with selection

For later

  • Add unit tests
  • Add support for defining column groups
  • Add a deltaPagination props to the component to customise the number of pages required before and after the active (currently only 2 possible)
  • Allow the use of ajax calls for searching and pagination

Summary Props

Table

NameTypeDefaultDescription
columnsArrayFor more information, please refer to the summary Table.columns
rowsArray-For more information, please refer to the summary Table.rows
labelString-Title for the table
descriptionString-Description for the table
isFilteredBooleanfalseA search input will be displayed with true value
rowsPerPageNumber10Number of items per page desired when the component is loaded
rowsPerPageOptionsNumber[]nullDefine the list of select options for the number of items to be displayed per page
sortFieldStringnullSpecify the column to be sorted by default when the component is loaded
checkboxSelectionBooleanfalseEach row becomes selectable with a checkbox and a ‘Select all’ for the column

Table.columns

NameTypeDefaultDescription
labelStringContent of a cell
isSortableBooleanIs the column sortable ?
cellStringkey associated with the contents of the desired cell

Table.rows

NameTypeDefaultDescription
idString | NumberId of a row
-String | Number | DateContent of a cell

Licence

1.0.2

1 year ago

1.0.1

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago

1.0.0

1 year ago