import React from 'react'; import { Switch, Table, Dropdown, Icon } from '@douyinfe/semi-ui'; import { IconCaretdown } from '@douyinfe/semi-icons'; const CREATOR_MAP = { ALL: { value: 0, desc: '创建者', }, MINE: { value: 1, desc: '只看我的', }, }; export default class JSXColumnsComplex extends React.Component { constructor(props) { super(props); this.state = { showName: true, showAge: true, showAddress: true, showCreator: true, currentCreator: {}, }; this.data = []; for (let i = 0; i < 46; i++) { this.data.push({ key: `${i}`, name: `Edward King ${i}`, age: (i * 1000) % 149 , address: `London, Park Lane no. ${i}`, }); } this.columns = [ { width: 150, onFilter: (value, record) => record.name.includes(value), filters: [ { text: 'Code 45', value: '45', }, { text: 'King 4', value: 'King 4', }, ], title: 'Name', dataIndex: 'name', render: (text, record, index) => {text}, }, { title: Age, dataIndex: 'age', sorter: (a, b) => (a.age - b.age > 0 ? 1 : -1), }, { title: ( 创建者 只看我的 )} > {this.state.currentCreator.desc} } /> ), key: 'creator', width: 168, }, { title: 'Address', dataIndex: 'address', }, ]; } setCreator(type) { this.setState({ currentCreator: { ...CREATOR_MAP[type] }, }); } toggleStatus = (type, status) => { this.setState({ [type]: status, }); }; render() { const { showAddress, showAge, showName, showCreator, currentCreator } = this.state; return (
显示名称 this.toggleStatus('showName', v)} />
显示年龄 this.toggleStatus('showAge', v)} />
显示创建者 this.toggleStatus('showCreator', v)} />
显示地址 this.toggleStatus('showAddress', v)} />
{showName ? ( record.name.includes(value)} filters={[ { text: 'Code 45', value: '45', }, { text: 'King 4', value: 'King 4', }, ]} title="Name" dataIndex="name" render={(text, record, index) => {text}} /> ) : null} {showAge ? ( Age} dataIndex="age" sorter={(a, b) => (a.age - b.age > 0 ? 1 : -1)} /> ) : null} {showCreator ? ( 创建者 只看我的 )} > {currentCreator.desc} } /> )} key={'creator'} /> ) : null} {showAddress ? : null}
); } }