0.2.3 • Published 3 months ago

react-native-data-table v0.2.3

Weekly downloads
67
License
MIT
Repository
github
Last release
3 months ago

react-native-data-table

A React Native data table written purely in JSX with React and RealmJS DB (until refactor).

DEPRECATED

Unfortunately we've stopped development of react-native apps at The mSupply Foundation, and thus this repo hasn't been maintained in a long time. react-native is amazing! We just had some unique requirements where we felt we could do better with rust and reactjs. As much as we've aspired to one day give this repo TLC, it hasn't happened so to be transparent we're finally putting this notice up. Sorry for the dead end!

If you're looking for inspiration to create your own table components:

Installation

npm install --save react-native-data-table

Usage

react-native-data-table provides a number of components for constructing a table through composition.

data table example

DataTable

This component acts as a wrapper around the React Native ListView component. All the other components in this library should be used in the renderRow and renderHeader.

Prop NameTypeDescription
ListView Props-Will pass through any extra props to ListView
listViewStylestyleWill override styling of the ListView within the DataTable
stylestyleStyle of the DataTable container (View)
dataSourceobject (required)See ListView
renderRowfunc (required)See RenderRow. Function can return anything, but the Cell components in this library are to make it easy for constructing a table
renderHeaderfuncProvide this function with appropriate return to make a table header
refCallbackfuncCallBack for utilising reference of the inner TextInput

Cell

Renders a Cell that supports having a string as children, or any component.

<Cell>Hello 1234</Cell>

Prop NameTypeDescription
textStylestyleWill override styling of the Text label within the button
stylestyleWill override styling of the TouchableHighlight enclosing the button
widthnumberGives width relative to other cells in the same container (via flexbox)
childrenanyContent of the cell; string, number or any component
numberOfLinesnumberDefines the number of lines in the cell that text should use

CheckableCell

Renders a CheckableCell that renders either renderIsChecked or renderIsNotChecked when isChecked is true or false respectively. Whole cell returned is pressable. Callback should affect state of Parent in some way that keeps the state of parent in sync with state of the CheckableCell. Kept separate to maintain responsiveness of the cell.

Prop NameTypeDescription
isCheckedbooleanUsed to set the initial state of the cell when the component mounts or rerenders (e.g. table sort order change)
isDisabledbooleanWill cause renderDisabled to be shown in the cell
stylestyleStyle of the CheckableCell (View props)
widthnumberGives width relative to other cells in the same container (via flexbox)
onPressfuncCallBack Function for handling user pressing CheckableCell
renderIsCheckedobjectObject is rendered as child in CheckableCell if checked
renderIsNotCheckedobjectObject is rendered as child in CheckableCell if not checked
renderDisabledobjectObject is rendered as child in CheckableCell if isDisabled is true

EditableCell

Renders a cell with an editable text input. Has own state for managing TextInput content and has onEndEditing callback for utilising user input.

Prop NameTypeDescription
TextInput Props-Will pass through any extra props to TextInput
textStylestyleWill override styling of the TextInput within the button
stylestyleStyle of the EditableCell (View props)
widthnumberGives width relative to other cells in the same container (via flexbox)
onEndEditingfuncWill be called with 2 params: target and the newValue on end of editing. This function should run code to persist the change to local storage
targetobjectData object of the row/record being edited
valuestring or numberProvides initial value. Will change what cell shows if prop changes
refCallbackfuncCallBack for utilising reference of the inner TextInput

Header

A container for header cells, should be the outermost component returned in the renderHeader function given to the DataTable renderHeader prop.

HeaderCell

Renders a headerCell that supports being a plain View with Text or being a TouchableOpacity (with callback). In the latter case sort arrows will be rendered and controlled with isSelected and isAscending props. This could also be thought of as "column headers", as that is what this component sets out to ultimately achieve.

Prop NameTypeDescription
TouchableOpacity Props-Will pass through any extra props to TouchableOpacity
textStylestyleWill override styling of the Text label within the HeaderCell
stylestyleWill override styling of the TouchableHighlight enclosing the button
widthnumberGives width relative to other cells in the same container (via flexbox)
onPressfuncCallBack Function for handling user pressing headerCell. Should change some parent state that affects the following 2 props
isSelectedBooleanWhen false up+down sort arrows renderHeader, otherwise as below
isAscendingBooleanSort arrow up if true, down if false.

Row

A container to be used in renderRow function in DataTable renderRow Prop. Has internal state that knows whether the row is expanded or not. Toggled on press. Will only render an expansion if provided.

renderRow(record) {
  <Row>
    <Cell>record.code</Cell>
    <Cell>record.name</Cell>
    <EditableCell
      value={record.quantity}
    />
  </Row>
}
Prop NameTypeDescription
stylestyleWill override styling of the TouchableHighlight enclosing the button
childrenanyContent of the Row; construct with Cell, EditableCell, etc.
onPressfuncCallBack for doing anything on the press of the row. Also toggles expansion
isExpandedbooleanIf true, the expansion defined renderExpansion will be shown below this row, moving other rows down.
renderExpansionfuncA function that should return an Expansion component with custom content

Expansion

Literally just a wrapper for View. To be used in the Row prop 'renderExpansion'. Made basically just for consistent semantics.

Prop NameTypeDescription
View Props-Will pass through any extra props to View

TableButton

Like expansion, this is essentially just a wrapper around TouchableOpacity with a default flex value of 1. Which I believe became redundant at some point in RN development.

0.2.3

3 months ago

0.2.2

1 year ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.6

6 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

8 years ago