0.0.3 • Published 6 years ago

react-native-simple-table v0.0.3

Weekly downloads
12
License
Apache-2.0
Repository
github
Last release
6 years ago

react-native-simple-table

A simple table for react native.

screenshot

Installation

npm install react-native-simple-table --save

Usage

import React, { Component } from 'react'
import {
  Platform,
  StyleSheet,
  View,
  Text
} from 'react-native'
import Table from 'react-native-simple-table'

import DataFactory from '../mock/DataFactory'

const columns = [
  {
    title: 'Mobile',
    dataIndex: 'mobile',
    width: 105
  },
  {
    title: 'Name',
    dataIndex: 'name',
    width: 140
  },
  {
    title: 'Age',
    dataIndex: 'age'
  },
  {
    title: 'Sex',
    dataIndex: 'sex'
  },
];

class Example extends Component {
  render() {
    let dataSource = DataFactory.generate().data;
    return (
      <View style={styles.container}>
        <Text style={styles.title}>react-native-simple-table</Text>
        <Table height={320} columnWidth={60} columns={columns} dataSource={dataSource} />
      </View>
    )
  }
}

const styles = StyleSheet.create({
  container: {
    ...Platform.select({
      ios: {
        paddingTop: 20
      },
      android: {}
    }),
  },
  title: {
    fontSize: 18,
    padding: 10,
    textAlign: 'center'
  }
});

export default Example
import mockjs, { Random } from 'mockjs'

export default class DataFactory {
  static generate() {
    return mockjs.mock({
      'data|1-20': [{
        'mobile|12300000000-12399999999': 1,
        'name|1': '@first @last',
        'age|18-80': 1,
        'sex|1': () => Random.pick(['male','female']),
      }]
    });
  }
}

API

Table

PropertyDescriptionTypeDefault
dataSourcedata record array to be renderedany[][]
columnscolumns of tableColumn[][]
columnWidthcolumn widthnumber60
renderCellrender functionfunctionundefined
heighttable heightnumber240

Column

PropertyDescriptionTypeDefault
titletitle of this columnstring-
dataIndexdisplay field of the data recordstring-
widthwidth of this columnnumber-