# @florinchristian.dev/rn-table

> rn-table is a flexible and intuitive way to wrap data like does in HTML.

Latest version **0.1.0-beta.0** (published 2022-08-31) · ISC license · 0 weekly downloads

## Install

```sh
npm install @florinchristian.dev/rn-table
pnpm add @florinchristian.dev/rn-table
yarn add @florinchristian.dev/rn-table
bun add @florinchristian.dev/rn-table
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0-beta.0 |
| Published | 2022-08-31 |
| First published | 2022-08-21 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 1.5 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | florinchristian |
| Maintainers | florinchristian.dev |
| Keywords | react native table, react table, react-native-table, rn-table |

## Links

- npm: https://www.npmjs.com/package/@florinchristian.dev/rn-table
- Repository: https://github.com/florinchristian/rn-table
- Homepage: https://github.com/florinchristian/rn-table#readme
- Issues: https://github.com/florinchristian/rn-table/issues
- npm.io page: https://npm.io/package/@florinchristian.dev/rn-table

## Alternatives

- [@lexical/table](https://npm.io/package/@lexical/table.md) — 3.0M weekly downloads
- [mantine-datatable](https://npm.io/package/mantine-datatable.md) — 98.2K weekly downloads
- [react-native-collapsible-tab-view](https://npm.io/package/react-native-collapsible-tab-view.md) — 70.6K weekly downloads
- [@handsontable/vue3](https://npm.io/package/@handsontable/vue3.md) — 16.1K weekly downloads
- [vuewordcloud](https://npm.io/package/vuewordcloud.md) — 7.2K weekly downloads

## Recent versions

- 0.1.0-beta.0 (latest) — 2022-08-31
- 0.0.1-beta.1 — 2022-08-21
- 0.0.1-beta.0 — 2022-08-21

## README

## rn-table

### Intro
rn-table is a flexible and intuitive way to wrap data like `<table>` does in HTML.

### Usage example

```js
import { Table } from "@florinchristian.dev/rn-table";
import dataWrapping from "./dataWrapping";

const App = () => {
  const [tableData, setTableData] = useState([
    {
      id: 1,
      Name: "Cristi",
      Age: 18,
      Address: "Pee Pee Island",
      Crimes: 69,
    },
    {
      id: 2,
      Name: "Kate",
      Age: 19,
      Address: "Freddy Fazbear Pizza",
      Crimes: 69,
    },
    {
      id: 3,
      Name: "Aura",
      Age: 19,
      Address: "Freddy Fazbear Pizza",
      Crimes: 69,
    },
    {
      id: 4,
      Name: "Devin",
      Age: 19,
      Address: "Freddy Fazbear Pizza",
      Crimes: 69,
    },
    {
      id: 5,
      Name: "Michael",
      Age: 19,
      Address: "Freddy Fazbear Pizza",
      Crimes: 69,
    },
  ]);

  const [selected, setSelected] = useState([]);
  const [toggle, setToggle] = useState(false);

  useEffect(() => {

  }, [toggle]);

  return (
    <SafeAreaView style={{
      flex: 1,
    }}>
      <Table
        data={tableData}
        dataWrapper={dataWrapping}
        fitWidth={false}
        uniqueKey={'id'}
        onCheck={selected => {
          setSelected(selected);
          setToggle(!toggle);
        }}
      />

      <View style={{
        flexDirection: 'column'
      }}>
        <Text>Selected:</Text>
        {selected.map(item => (
          <Text>{item}</Text>
        ))}
      </View>
    </SafeAreaView>
  );
};
```

### Preview

<table cellpadding="0">
  <tr style="padding: 0">
    <tr>
      <th>fitWidth: false</th>
      <th>fitWidth: true</th>
     </tr>
    <td valign="top"><img src="https://github.com/florinchristian/rn-table/blob/master/preview-1.gif" width="300"></td>
    <td valign="top"><img src="https://github.com/florinchristian/rn-table/blob/master/preview-2.png" width="300"></td>
  </tr>
</table>

### Mandatory props
- `data`
  - Data model:
  ```js
    // Note that the identifier of each field will appear exactly the same in the table header
    {
      uniqueKey: 1,
      Field1: "Cristi",
      Field2: 18,
      Field3: "Pee Pee Island",
      Field4: 69
    }
  ```
- `dataWrapper`
  - Data wrapper model:
  ```js
    // Note 1: cellWidth & component properties are mandatory
    // Note 2: cellWidth assures the styling of the table; component tells
    //  the table what component to render for each table field and its data
    // Note 3: each field must be the same as the fields in the data model
    const dataWrapping = {
    "Field1": {
      cellWidth: 100,
      component: (item) => (
        <Text style={{
          color: 'black'
        }}>{item}</Text>
      )
    },
    "Field2": {
      cellWidth: 100,
      component: (item) => (
        <Text style={{
          color: 'black'
        }}>{item}</Text>
      )
    },
    "Field3": {
      cellWidth: 150,
      component: (item) => (
        <Text style={{
          color: 'black'
        }}>{item}</Text>
      )
    },
    "Field4": {
      cellWidth: 150,
      component: (item) => (
        <Text style={{
          color: 'black'
        }}>{item}</Text>
      )
    },
  };
  ```
- `uniqueKey` : is the exact path to the property in the data model that identifies the object.
  For instance:
  ```js
  // the uniqueKey for the data model below is 'id'
  {
      id: 1,
      Name: "Cristi",
      Age: 18,
      Address: "Pee Pee Island",
      Crimes: 69,
  }
  ```
- `onCheck` : is the method called every time an item is selected.
  ```js
  onCheck={selected => {
    // selected is an array of the selected items (their unique keys)
  }}
  ```
  
### Optional props
- `fitWidth` : this prop tells the table whether to fit the device's width or to enlarge as much as needed.
- `headerStyle` : this prop contains a `StyleSheet` object used to apply a custom style to the header.
- `oddRowStyle` : this prop contains a `StyleSheet` object used to apply a custom style to the odd-indexed rows.
- `evenRowStyle` : this prop contains a `StyleSheet` object used to apply a custom style to the even-indexed rows.
- `containerStyle` : this prop contains a `StyleSheet` object used to apply a custom style to the view containing the rows.

---
_Source: https://npm.io/package/@florinchristian.dev/rn-table · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
