<!--
/* Font Definitions */
@font-face
{font-family:"Source Sans Pro";
panose-1:2 11 5 3 3 4 3 2 2 4;
mso-font-charset:0;
mso-generic-font-family:swiss;
mso-font-pitch:variable;
mso-font-signature:1610613495 33554433 0 0 415 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-unhide:no;
mso-style-qformat:yes;
mso-style-parent:"";
margin:0in;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:"Times New Roman","serif";
mso-fareast-font-family:"Times New Roman";
mso-fareast-theme-font:minor-fareast;}
a:link, span.MsoHyperlink
{mso-style-noshow:yes;
mso-style-priority:99;
color:blue;
text-decoration:underline;
text-underline:single;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-noshow:yes;
mso-style-priority:99;
color:purple;
mso-themecolor:followedhyperlink;
text-decoration:underline;
text-underline:single;}
span.SpellE
{mso-style-name:"";
mso-spl-e:yes;}
span.GramE
{mso-style-name:"";
mso-gram-e:yes;}
.MsoChpDefault
{mso-style-type:export-only;
mso-default-props:yes;
font-size:10.0pt;
mso-ansi-font-size:10.0pt;
mso-bidi-font-size:10.0pt;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;
mso-header-margin:.5in;
mso-footer-margin:.5in;
mso-paper-source:0;}
div.WordSection1
{page:WordSection1;}
-->
A reusable responsive react.js table component
with sorting and filtering options. Sorting and filtering can be configurable easily with
column items of data.
Demo
https://reusable-table-component.firebaseapp.com/
Usage
Use react-reusable-table as below.
import React from 'react'
import { Table } from 'react-reusable-table'
const App = () => (
<div className="App">
<Table
caption=""
data={this.props.records}
detailPage={this.detailPageHandler}
footerCells={utility.getHeaderCells()}
headerCells={utility.getHeaderCells()}
showFooter={false}
sortedUporDown={this.sortRecordsHandler}/>
);
// utility.js
// getHeaderCells method
export const getHeaderCells = () => {
return [
{ label: 'ID', name: 'id', isFilterAble:
false, isSortAble: false },
{ label: 'Status', name: 'status', isFilterAble:
true, isSortAble: false },
{ label: 'Machine Type', name: 'machine_type',
isFilterAble: true, isSortAble:
false },
{ label: 'Longitude', name: 'longitude', isFilterAble:
false, isSortAble: true },
{ label: 'Latitude', name: 'latitude', isFilterAble:
false, isSortAble: true },
{ label: 'Last Maintenance', name: 'last_maintenance',
isFilterAble: false, isSortAble:
true },
{ label: 'Install Date', name: 'install_date',
isFilterAble: false, isSortAble:
true },
{ label: 'Floor', name: 'floor', isFilterAble:
true, isSortAble: false }
]
}
// sort records
in asc or desc order
sortRecordsHandler = (colName, sortType) => {
this.props.onSortRecords(colName, sortType);
}
// go to detail
page
detailPageHandler = (id) => {
this.props.history.push('records/' + id);
}
// sample records
{
"data": [
{
"status": "running",
"machine_type": "microscope",
"longitude": 48.09540056785246,
"latitude": 11.523880271993598,
"last_maintenance":
"2017-04-01T15:00:00.000000Z",
"install_date": "2015-04-18",
"id": "68015cc1-3119-42d2-9d4e-3e824723fe03",
"floor": 5
},
{
"status": "running",
"machine_type": "microscope",
"longitude": 48.09535029616455,
"latitude": 11.523869432452495,
"last_maintenance":
"2017-04-01T14:00:00.000000Z",
"install_date": "2015-04-11",
"id": "59d9f4b4-018f-43d8-92d0-c51de7d987e5",
"floor": 4
}
]
}
Sorting & Filtering
Sorting and filtering can be configurable using any column
items from the records. In the above configurable method getHeaderCells there are two flags isFilterAble
and isSortAble can be set for
each of the column items for records. So setting true any of them will enable
the filter or sort option for column items.
Installation
npm
npm i react-reusable-table --save
yarn
yarn add react-reusable-table