1.0.4 • Published 3 years ago

react-native-table-optimize v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

React Native Table Optimize 🇻🇳

The package is both Android and iOS compatible.

Try it out

Have a look at the examples below! :-)

Installation

  1. Install as dependency:
// yarn
yarn add react-native-table-optimize

// or npm
npm i react-native-table-optimize
  1. Add needed components:
import { TableWrap, TableHead, TableBody, TableRow } from 'react-native-table-optimize';

Props

TableWrap

PropDefaultTypeDescription
children-React.ReactNodeChildren. Should be of type Section
width100%stringLength of percentage table with screen size
scrollHorizontalfalseboolAllow horizontal dragging of the table if the length of the board exceeds 100%

TableHead

PropDefaultTypeDescription
titleTextStyle-Text.propTypes.styleThese styles will be applied to the title text table.
itemStyle-View.propTypes.styleThese styles will be applied to the box (row - col) in table.
dataTitleHead-arrayAn array of text corresponding to each column heading
dataSpacing-arrayA text array of percentage distances for each column

TableBody

PropDefaultTypeDescription
children-React.ReactNodeChildren. Should contains the rows of the table
isScrollfalseboolAllow scrolling up and down and fix the table title
bodyHeight300numberTable content height
bodyStyle_View.propTypes.styleThese styles will be applied to the content of table
onRefreshTable_funcListen to refresh table event

TableRow

PropDefaultTypeDescription
width100%React.ReactNodeLength of percentage table with screen size
textStyle_Text.propTypes.styleThese styles will be applied to the row text table.
itemStyle_View.propTypes.styleThese styles will be applied to the item row table.
dataRow_arrayAn array of text corresponding to each column row
dataSpacing_arrayA text array of percentage distances for each row
onHandleItemRow_funcListen to onPress event of item

Examples

import { TableWrap, TableHead, TableBody, TableRow } from 'react-native-table-optimize';
export default function App() {

  return (
      <ScrollView>
          <Text style={{textAlign: 'center', paddingVertical: 30, marginTop: 30, fontWeight: '700', fontSize: 20}}>Table Native Table Optimize</Text>
          <TableWrap width='125%' scrollHorizontal={true}> 
              <TableHead
                  dataSpacing={dataSpacing}
                  dataTitleHead={dataTitleTHead}
                  itemStyle={{
                      backgroundColor: THEME.PRIMARY_COLOR_LIGHT,
                      padding: 10,
                      borderWidth: 1,
                      borderColor: THEME.PRIMARY_COLOR_DARK,
                  }}
                  titleTextStyle={{
                      textAlign: 'center',
                      color: THEME.BLACK_COLOR,
                      fontWeight: '700'
                  }}
              />
              <TableBody
                  isScroll={true}
                  bodyHeight={465}
                  onRefreshTable={() => {
                      Alert.alert('On RefreshDataTable')
                  }}
              >
                  {
                      dataRow.map((item, idx) => {
                          let itemRow = [
                              item.content1,
                              item.content2,
                              item.content3,
                              item.content4,
                              item.content5,
                          ]
                          return (
                              <TableRow 
                                  key={idx}
                                  width='100%' 
                                  dataSpacing={dataSpacing}      
                                  dataRow={itemRow}    
                                  textStyle={{
                                      textAlign: 'center',
                                      color: THEME.BLACK_COLOR
                                  }}
                                  itemStyle={{
                                      backgroundColor: THEME.WHITE_COLOR,
                                      padding: 10,
                                      borderWidth: 1,
                                      borderColor: THEME.PRIMARY_COLOR_LIGHT,
                                  }}         
                                  onHandleItemRow={() => Alert.alert('On Touch Row')}            
                              />
                          )
                      })
                  }
              </TableBody>
          </TableWrap>
      </ScrollView>
  );
}