--- order: 5 title: zh-CN: 表格穿梭框 en-US: Table Transfer --- ## zh-CN 使用 Table 组件作为自定义渲染列表。 ## en-US Customize render list with Table component. ```jsx import { Transfer, Switch, Table, Tag } from 'antd'; import difference from 'lodash/difference'; // Customize Table Transfer const TableTransfer = ({ leftColumns, rightColumns, ...restProps }) => ( {({ direction, filteredItems, onItemSelectAll, onItemSelect, selectedKeys: listSelectedKeys, disabled: listDisabled, }) => { const columns = direction === 'left' ? leftColumns : rightColumns; const rowSelection = { getCheckboxProps: item => ({ disabled: listDisabled || item.disabled }), onSelectAll(selected, selectedRows) { const treeSelectedKeys = selectedRows .filter(item => !item.disabled) .map(({ key }) => key); const diffKeys = selected ? difference(treeSelectedKeys, listSelectedKeys) : difference(listSelectedKeys, treeSelectedKeys); onItemSelectAll(diffKeys, selected); }, onSelect({ key }, selected) { onItemSelect(key, selected); }, selectedRowKeys: listSelectedKeys, }; return ( ({ onClick: () => { if (itemDisabled || listDisabled) return; onItemSelect(key, !listSelectedKeys.includes(key)); }, })} /> ); }} ); const mockTags = ['cat', 'dog', 'bird']; const mockData = []; for (let i = 0; i < 20; i++) { mockData.push({ key: i.toString(), title: `content${i + 1}`, description: `description of content${i + 1}`, disabled: i % 4 === 0, tag: mockTags[i % 3], }); } const originTargetKeys = mockData.filter(item => +item.key % 3 > 1).map(item => item.key); const leftTableColumns = [ { dataIndex: 'title', title: 'Name', }, { dataIndex: 'tag', title: 'Tag', render: tag => {tag}, }, { dataIndex: 'description', title: 'Description', }, ]; const rightTableColumns = [ { dataIndex: 'title', title: 'Name', }, ]; class App extends React.Component { state = { targetKeys: originTargetKeys, disabled: false, showSearch: false, }; onChange = nextTargetKeys => { this.setState({ targetKeys: nextTargetKeys }); }; triggerDisable = disabled => { this.setState({ disabled }); }; triggerShowSearch = showSearch => { this.setState({ showSearch }); }; render() { const { targetKeys, disabled, showSearch } = this.state; return (
item.title.indexOf(inputValue) !== -1 || item.tag.indexOf(inputValue) !== -1 } leftColumns={leftTableColumns} rightColumns={rightTableColumns} />
); } } ReactDOM.render(, mountNode); ```