Socket
Book a DemoInstallSign in
Socket

react-native-data-table

Package Overview
Dependencies
Maintainers
3
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-data-table

A generic table to lay out data from realm for react native

0.2.3
latest
Source
npmnpm
Version published
Weekly downloads
108
11.34%
Maintainers
3
Weekly downloads
 
Created
Source

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:

  • In our app mSupply Mobile, we largely rewrote react-native-data-table! But didn't have the resources to polish it up and republish here :(.
  • Try replicate something similar to shadcn's reactjs DataTable.

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.

FAQs

Package last updated on 25 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.