0.3.17 • Published 6 months ago

frame-one-table v0.3.17

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Frame One Table Logo NPM NPM GITHUB

➡️ Try out the table in the Storybook! ⬅️

version 0.2.0 had some big changes to how data is passed around, will document eventually

Installation

npm

npm install frame-one-table

yarn

yarn add frame-one-table

Usage

Use Frame One Table's TableGenerator component like any React component; and pass it props to configure your table as desired.

import * as React from 'react'
import {TableGenerator} from "frame-one-table";

class Example extends React.Component {
  render () {
    return (
      <TableGenerator
        columnOptions={[]}
        data={[]}
      />
    )
  }
}

Props

Table Generator TableGeneratorProps

PropTypeDescription
dataTableDataPass in the data here to be rendered
columnOptionsColumnOption[]Options to determine the rendering of each column
paginatorPropsIPaginatorProps[]Props for controlling the paginator
sortablebooleanDetermine a default for each column as sortable. This can be overridden by the columnOptions
showSortIconsbooleanToggle to hide or show the arrow icons in the header cells when a column is sortable. Defaults true
showHeaderbooleanHide or show the header row. Defaults true
showBodybooleanHide or show the body part of the table. Not sure why you would want to hide it if you are using this library. Defaults true
headerClassNamestringclassName applied to the header row
rowClassNamestringclassName applied to each row in the body
headerCellClassNamestringclassName applied to each cell in the header row
rowCellClassNamestringclassName applied to each cell in the table body
headerStyleCSSPropertiesstyle tag applied to the header row
rowStyleCSSPropertiesstyle tag applied to each row in the body
headerCellStyleCSSPropertiesstyle tag applied to each cell in the header row
rowCellStyleCSSPropertiesstyle tag applied to each cell in the table body
rowFilterContextFunctionRow<boolean>filter out rows that are shown // TODO
paginationControlsRenderContextFunctionPagination<ReactNode>create your own pagination controls // TODO
loadingbooleanloading, its nice to use this instead of increment loading since we can just block a table // TODO
loadingOverlayContextFunctionData<ReactNode>loading, its nice to use this instead of increment loading since we can just block a table // TODO

Column Options ColumnOption

PropTypeDescription
keystring numberkey that is used to extract the correct value from the row's object (string) or array (number)
headerValueanyLabel for the header cell (ie. First Name)
valueFormatterContextFunctionCell<any>Format function to run the values for the column's body cells through before displaying them (ie. (height) => height + "cm"). Does not modify the value used to compare for sorting the column
headerRenderContextFunctionCell<ReactNode>Custom render function for the header cell
cellRenderContextFunctionCell<ReactNode>Custom render function for the body cells of this column
headerCellClassNamestringclassName applied to the header cell
rowCellClassNamestringclassName applied to the body cells of this column
headerCellStyleCSSPropertiesstyle tag applied to the header cell
rowCellStyleCSSPropertiesstyle tag applied to the body cells of this column
sortablebooleanToggle if this column can be sorted. Takes precedent over the "sortable" prop from TableGeneratorProps
showSortIconsbooleanToggle to hide or show the arrow icons in the header cell if the column is sortable. Takes precedent of the "showSortIcons" props from TableGeneratorProps
sortFunction(a: any, b: any, aRow: TableDataEntry, bRow: TableDataEntry, data: TableData, columns: ColumnOption[], sortConfiguration: ISortStyle) => numberCustom sort function for the column where a & b are the values. If not custom sort is applied, the library will attempt to sort automatically based on the primitive data type
hiddenbooleanToggle for hiding a column... Perhaps if a column becomes hidden based on certain conditions on your end, change this to false instead of creating a whole new set of column options

Paginator Props IPaginatorProps

PropTypeDescription
showbooleanShow or hide the paginator. Defaults false
limitLabelstringString shown next to the drop-down for choosing the limit (ie. Showing X - Y of Z)
currentLimitnumberCurrently selected limit for the table
limitOptionsnumber[]Array of numbers representing options for what limits can be chosen via the drop-down
totalnumberTotal number of results in the table or pool of data. Used to calculate the last index for the "go to last" button
onLimitChange(newLimit: number) => voidHandler for changing the limit per page via the drop-down
enableGoPreviousbooleanToggle for if the "go to first" and "previous" buttons should be enabled
enableGoNextbooleanToggle for if the "go to last" and "next" buttons should be enabled
showGoToFirstButtonbooleanHide or show the "go to first" button. Defaults true
showGoToLastButtonbooleanHide or show the "go to last" button. Defaults true
currentOffsetnumberCurrent offset of the pagination, indexed at 0
availableOffsetsnumber[]Array of numbers for which pages should be accessible via the paginator (indexed at 0 - ie. 0, 1, 2, 3, 4, will be displayed as 1, 2, 3, 4 ,5 by the library)
onOffsetChange(newOffset: number) => voidHandler for changing the selected offset page

Table Data Types

NameTypeNotes
TableDataEntryArrayany[]// TODO; currently not supported
TableDataEntryJSON{[key: string]: any}
TableDataArray<TableDataEntryArray> or Array<TableDataEntryJSON>The data for the table
TableDataEntryTableDataEntryArray or TableDataEntryJSONRepresents a single row
TableDataEntryTableDataEntryArray or TableDataEntryJSONRepresents a single row

Context Helpers

NameType
ContextFunctionData<R>(data: TableData) => R
ContextFunctionCell<R>(value: any, row: TableDataEntryArray or TableDataEntryJSON, key: string or number, data: TableData, index?: number) => R
ContextFunctionRow<R>(row: TableDataEntryArray or TableDataEntryJSON, key: string or number, data: TableData, index?: number) => R
ContextFunctionPagination<R>(pageSize: number, pageIndex: number, goToPage: (page: number) => void, data: TableData) => R
0.3.17

6 months ago

0.3.15

11 months ago

0.3.13

11 months ago

0.3.12

2 years ago

0.3.9

2 years ago

0.3.11

2 years ago

0.3.10

2 years ago

0.3.6

2 years ago

0.3.8

2 years ago

0.3.7

2 years ago

0.3.1

2 years ago

0.3.4

2 years ago

0.2.10

2 years ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.9

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.1.10

2 years ago

0.2.0

2 years ago

0.2.2

2 years ago

0.1.9

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago