2.2.0 • Published 8 years ago

@ubc-farm/table-base v2.2.0

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

@ubc-farm/table-base

Basic Table component for React that takes a JSON array and column descriptor elements to render a table.

import TableBase, { Column } from '@ubc-farm/table-base';

const tableData = [
  {id: 1, name: "name1", price: 100},
  {id: 2, name: "name2", price: 120},
  {id: 3, name: "name3", price: 130},
  {id: 4, name: "name4", price: 140},
  {id: 5, name: "name5", price: 110}
];

<TableBase tableData={tableData}>
	<Column field="id" isKey>ID</Column>
	<Column field="name">Name</Column>
	<Column field="price"><em>Price ($)</em></Column>
</TableBase>

Usage

Table props

nametypedescription
childrenColumn[]Column descriptors
tableDataObject[]Data to render
keyFieldstringThe key field in each object. Can alternatively be specified in the Column
rowClassNamestring | functionAdditional className for rows. If a function, will be called to obtain the class for a given row ((row, rowIndex) => string)
tableClassNamestringClass for the table container.
headClassNamestringClass for the table head
bodyClassNamestringClass for the table body
headRowClassNamestringClass for the row inside the table head
onRowClickfunctionClick handler with (row, event) arguments
onRowMouseEnterfunctionMouse enter handler with (row, event) arguments
onRowMouseLeavefunctionMouse leave handler with (row, event) arguments
onMouseEnterfunctionMouse enter handler for the entire table
onMouseLeavefunctionMouse leave handler for the entire table

Column props

nametypedescription
fieldstringThe object key this column corresponds to
childrenReactNodeContent to show in the table header cell
isKeybooleanSets the column as the key field for each JSON object. Alternative to Table keyField
formatfunctionFunction to format cell data: (cell, row) => ReactNode
hiddenbooleanIf true, column is hidden from view
columnClassNamestring | functionClasses for cells in the column. If a function, will be called to obtain the class for a given cell ((cell, row, rowIndex) => string)
headerClassNamestringClass for the header cell corresponding to the column
onHeaderClickfunctionClick event for the header cell
onCellClickfunctionClick handler for cells in this column (takes (cell, row, rowIndex)).
2.2.1

8 years ago

2.2.0

9 years ago

2.1.0

9 years ago

2.0.0

9 years ago