0.0.6 • Published 2 years ago

react-ab-data-table v0.0.6

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

react-ab-dataTable

Was made for a student projet for OpenClassrooms.

This library is a react component to render a table using two arrays of objects.

The table can be sorted, filtered (using a search input), paginated and the number of row can be change (all can be disable).

Documentation

Installation

Run the following command:

# If you use npm:
npm install react-ab-data-table

# If you use yarn:
yarn add react-ab-data-table

Usage

import { DataTable } from "react-ab-data-table";

const App = () => {
	const columns = [
		{ name: "First Name", id: "firstName", sortable: true },
		{ name: "Last Name", id: "lastName", sortable: true },
		{ name: "City", id: "city", sortable: true },
		{ name: "Birthday", id: "birthday", sortable: true },
	];

	const data = [
		{ firstName: "John", lastName: "Doe", city: "New York", birthday: "1980-01-02" },
		{ firstName: "Jane", lastName: "Doe", city: "Los Angeles", birthday: "1985-02-14" },
		{ firstName: "John", lastName: "Smith", city: "Chicago", birthday: "1970-11-22" },
		{ firstName: "Jane", lastName: "Smith", city: "Houston", birthday: "1975-09-30" },
	];

	return (
		<main>
			<DataTable columns={columns} data={data} tableId="employee" sortId="lastName" />
		</main>
	);
};

Columns array

This array is use to render the head columns

  • name: the name of the column displayed in the table header
  • id: the id of the column
  • sortable: boolean, if the column is sortable
  • headColSpan: size of the column in the header bodyColSpan: size of the column in the body

Data array

This array must contain the data of the table, every object will be a row.

The key must be the id of the column and the value will be the data in the row/column.

Props list

NameTypeRequiredDescriptionDefault
dataarrayOfYesThe data to be displayed in the table
columnsarrayOfYesThe columns to be displayed in the table
tableIdstringYesThe id of the table
sortIdstringNoThe id of the column to be sortedfunction()
itemsPerPageOptionsarrayNoThe options for the items per page dropdown10, 25, 50, 100
itemsPerPageSelectionEnabledboolNoWhether the items per page dropdown should be enabledtrue
searchEnabledboolNoWhether the search input should be enabledtrue
sortSelectionEnabledboolNoWhether the sort dropdown should be enabledtrue
tableInfoEnabledboolNoWhether the table info should be enabledtrue
paginationEnabledboolNoWhether the pagination should be enabledtrue
dataTablesWrapperClassNamestringNoThe class name of the wrapper div"data-tables-wrapper"
dataTablesLengthClassNamestringNoThe class name of the length div"data-tables-length"
dataTablesLengthLabelClassNamestringNoThe class name of the length label"data-tables-length-label"
dataTablesLengthSelectClassNamestringNoThe class name of the length select"data-tables-length-select"
dataTablesLengthOptionClassNamestringNoThe class name of the length options"data-tables-length-option"
dataTablesSearchWrapperClassNamestringNoThe class name of the search wrapper div"data-tables-search-wrapper"
dataTablesSearchLabelClassNamestringNoThe class name of the search label"form-label"
dataTablesSearchInputClassNamestringNoThe class name of the search input"form-input"
dataTablesInfoClassNamestringNoThe class name of the info div"data-tables-info"
dataTablesPaginateClassNamestringNoThe class name of the paginate div"data-tables-paginate"
dataTableClassNamestringNoThe class name of the table"data-table"
dataTableHeaderClassNamestringNoThe class name of the table header"data-table-header"
dataTableHeaderTrClassNamestringNoThe class name of the table header tr"data-table-header-tr"
dataTableHeaderThClassNamestringNoThe class name of the table header th"data-table-header-th"
dataTableHeaderSortedClassNamestringNoThe class name of the table header th sorted"sorting"
dataTableBodyClassNamestringNoThe class name of the table body"data-table-body"
dataTableBodyTrClassNamestringNoThe class name of the table body tr"data-table-body-tr"
dataTableBodyTdClassNamestringNoThe class name of the table body td"data-table-body-td"
dataTableBodyTdSortedClassNamestringNoThe class name of the table body td sorted"sorting_1"
dataTableBodyTdEmptyClassNamestringNoThe class name of the table body td empty"data-tables-empty"
dataTableBodyOddRowClassNamestringNoThe class name of the table body tr odd"odd"
dataTableBodyEvenRowClassNamestringNoThe class name of the table body tr even"even"

Author

Arthur Blanc : GitHub - Portfolio

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago