TabDetailView.js 2.86 KB
import React, {Component} from 'react';
import {
    View,
    Text,
    TextInput,
    Image,
} from 'react-native';
import {
    Cell,
    DataTable,
    Header,
    HeaderCell,
    Row,
    EditableCell,
    CheckableCell,
} from 'react-native-data-table';

/**
 * 表格/明细 组件
 */
export default class TabDetailView extends Component {

    constructor(props) {
        super(props);
    }

    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>
        );
    }

    render() {
        return(
            <View style={{width: '100%', backgroundColor: 'white', paddingHorizontal: 5, paddingVertical: 10}}>
                <DataTable
                    style={styles.container}
                    listViewStyle={styles.container}
                    dataSource={this.state.ds}
                    renderRow={this.renderRow}
                    renderHeader={this.renderHeader}
                />
            </View>
        );
    }
}