React Native 表格组件
发布时间:2020-12-15 06:34:45 所属栏目:百科 来源:网络整理
导读:本文原创首发于公众号:ReactNative开发圈,转载需注明出处。 React Native 表格组件:react-native-data-table,纯JS组件,功能强大。支持自定义表头、行、单元格样式。支持编辑单元格和选择列。还能显示子行。 效果图 安装方法 npm install --save react-n
本文原创首发于公众号:ReactNative开发圈,转载需注明出处。 React Native 表格组件:react-native-data-table,纯JS组件,功能强大。支持自定义表头、行、单元格样式。支持编辑单元格和选择列。还能显示子行。 效果图
安装方法
组件说明表格组件主要分成以下几部分:DataTable 表格 使用示例import { Cell,DataTable,Header,HeaderCell,Row,EditableCell,CheckableCell,} from 'react-native-data-table'; render() { return ( <View style={styles.container}> <DataTable style={styles.container} listViewStyle={styles.container} dataSource={this.state.ds} renderRow={this.renderRow} renderHeader={this.renderHeader} /> </View> ); } renderHeader() { return ( <Header> <HeaderCell style={styles.headerCell} key="1" text="选择" width={1} /> <HeaderCell style={styles.headerCell} key="2" text="序号" width={1} onPress={() => this.onColumnSort()} /> <HeaderCell style={styles.headerCell} key="3" text="科室名称" width={3} isAscending={false} onPress={() => this.onColumnSort()} /> <HeaderCell style={styles.headerCell} key="4" text="数量" width={1} isAscending={false} onPress={() => this.onColumnSort()} /> </Header> ); } renderRow(item) { let rowStyle = item.no%2 === 0 ? styles.whiteRow : styles.row; return ( <Row style={rowStyle}> <CheckableCell style={styles.cell} width={1} onPress={() => this.onCheckablePress()} renderIsChecked={() => ( <Icon name="checkbox-blank-outline" size={20} color="blue" /> )} renderIsNotChecked={() => ( <Icon name="checkbox-marked" size={20} color="blue" /> )} isChecked={item.isChecked} /> <Cell style={styles.cell} width={1}> {item.no} </Cell> <Cell style={styles.cell} width={3}> {item.name} </Cell> <EditableCell width={1} value={item.qty} onEndEditing={(target,value) => {}}> </EditableCell> </Row> ); } onCheckablePress() {} onColumnSort() {} 完整示例完整代码:https://github.com/forrest23/... 组件地址https://github.com/sussol/rea... 微信不让跳转外链,可以点击查看原文来查看外链GitHub内容。 举手之劳关注我的微信公众号:ReactNative开发圈 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |