1.0.5 • Published 2 years ago

react-custable v1.0.5

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

preview

This component will suitable for you if

You want

a selectable react table ?

to render a component inside the table cell ?

a table with beautiful pagination?

Run component in storybook

First clone the source then run

npm start

Install via NPM:

npm install --save react-custable

Usage

Just two variable is needed, column and data

import { Table } from 'react-custable';

//the fieldName should be as same as data's key
const column = [
  { fieldName: 'name', title: 'Name', width: '180px', sortable: true },
  { fieldName: 'email', title: 'Email', width: '180px', sortable: true },
];

const data = [
  { id: '1', name: 'name one', email: 'mailone@mail.com' },
  { id: '2', name: 'name two', email: 'mailtwo@mail.com' },
];
<div className="App">
  <Table columns={columns} data={data} />
</div>;

Column Options

OptionTypeDescription
fieldName*stringdata key
title*stringcolumn header title
widthstring(px)column width (Default is auto)
fixedstring ('left' or 'right')if you want to fixed the column (only work for first column or last column)
sortablebooleanis column sortable (Default is false), string sort
sortFunc( a , b ) => numbersort function for column //return -1 when a < b , 1 when a > b , 0 when a = b
render(row: T, index: number) => Cellfor rendering custom component in cell

Cell

type Cell = {
  value: React.ReactNode,
  props: { [key: string]: string }, //props will be applied to td elemenet like colspan
};

Table Options

OptionTypeDescription
column*Column[]array of columns
data*{ id:string, ... }[]array of data
selectRowHandler(selectedRowIds: string[]) => voidthe callback function will receiver selected row IDs
selectedRowKeysstring[]default value for selected rows
pagination{ currentPage: number; totalCount: number; pageLimit: number; }values for table pagination
pageChangeHandler(pageNumner: number) => voidthe callback for handle page changes
rowClickHandler(row: Row) => voidthe callback for handle row click
showLoadingbooleanshow spinner over table