| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- import React from 'react';
- import { Table, Pagination, ButtonGroup, Button, Switch } from '../../../index';
- export default class RenderPagination extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- customPagination: true,
- pagination: { ...props.pagination, pageSize: 8 },
- };
- this.renderPagination = pagination => {
- return <Pagination {...pagination} />;
- };
- this.switchPagination = position => {
- let { pagination } = this.state;
- const positions = ['bottom', 'top', 'both'];
- if (position === true || position === false) {
- pagination = position ? { ...pagination } : false;
- } else if (positions.includes(position)) {
- pagination = { ...pagination, position };
- }
- this.setState({ pagination });
- };
- this.toggleRenderPagination = checked => {
- this.setState({ customPagination: checked });
- };
- this.TableSwitch = function TableSwitch({
- text,
- children,
- checked,
- onChange,
- style = { display: 'inline-flex', alignItems: 'center', margin: 5 },
- }) {
- const switchProps = { onChange };
- if (checked != null) {
- switchProps.checked = !!checked;
- }
- return (
- <span style={style}>
- <span>{text}</span>
- {children != null ? children : <Switch size="small" {...switchProps} />}
- </span>
- );
- };
- this.data = [
- {
- key: '1',
- name: 'John Brown',
- age: 32,
- address: 'New York No. 1 Lake Park, New York No. 1 Lake Park',
- },
- {
- key: '2',
- name: 'Jim Green',
- age: 42,
- address: 'London No. 1 Lake Park',
- },
- {
- key: '3',
- name: 'Joe Black',
- age: 32,
- address: 'Sidney No. 1 Lake Park',
- },
- {
- key: '4',
- name: 'Disabled User',
- age: 99,
- address: 'Sidney No. 1 Lake Park',
- },
- {
- key: '5',
- name: 'John Brown',
- age: 32,
- address: 'New York No. 1 Lake Park, New York No. 1 Lake Park',
- },
- {
- key: '6',
- name: 'Jim Green',
- age: 42,
- address: 'London No. 1 Lake Park',
- },
- {
- key: '7',
- name: 'Joe Black',
- age: 32,
- address: 'Sidney No. 1 Lake Park',
- },
- {
- key: '8',
- name: 'Disabled User',
- age: 99,
- address: 'Sidney No. 1 Lake Park',
- },
- {
- key: '9',
- name: 'John Brown',
- age: 32,
- address: 'New York No. 1 Lake Park, New York No. 1 Lake Park',
- },
- {
- key: '10',
- name: 'Jim Green',
- age: 42,
- address: 'London No. 1 Lake Park',
- },
- {
- key: '11',
- name: 'Joe Black',
- age: 32,
- address: 'Sidney No. 1 Lake Park',
- },
- {
- key: '12',
- name: 'Disabled User',
- age: 99,
- address: 'Sidney No. 1 Lake Park',
- },
- ];
- }
- render() {
- const TableSwitch = this.TableSwitch;
- const { customPagination, pagination } = this.state;
- return (
- <div>
- <div>
- <TableSwitch text="自定义渲染分页" checked={customPagination} onChange={this.toggleRenderPagination} />
- <TableSwitch text="分页器位置">
- <ButtonGroup>
- <Button onClick={() => this.switchPagination('bottom')}>Bottom</Button>
- <Button onClick={() => this.switchPagination('top')}>Top</Button>
- <Button onClick={() => this.switchPagination('both')}>Both</Button>
- <Button onClick={() => this.switchPagination(false)}>None</Button>
- </ButtonGroup>
- </TableSwitch>
- </div>
- <Table dataSource={this.data} pagination={pagination} renderPagination={customPagination ? this.renderPagination : null}>
- <Table.Column
- title="Name"
- dataIndex="name"
- key="name"
- render={(text, record, index) => <a>{text}</a>}
- />
- <Table.Column title="Age" dataIndex="age" key="age" />
- <Table.Column title="Address" dataIndex="address" key="address" />
- </Table>
- </div>
- );
- }
- }
|