image.png

    1. import { BaseTable, useTablePipeline, features } from 'ali-react-table';
    2. import { Table } from 'antd';
    3. const dataSource = [
    4. { prov: '湖北省', settled: 54406, flow: 4793, add: 1457, t: '2020-02-15 19:52:02' },
    5. { prov: '广东省', settled: 1294, flow: 409, add: 2, t: '2020-02-15 19:52:02' },
    6. { prov: '河南省', settled: 1212, flow: 390, add: 13, t: '2020-02-15 19:52:02' },
    7. { prov: '浙江省', settled: 1162, flow: 428, add: 0, t: '2020-02-15 19:52:02' },
    8. { prov: '湖南省', settled: 1001, flow: 417, add: 2, t: '2020-02-15 19:52:02' },
    9. ];
    10. const columns = [
    11. { code: 'prov', name: '省份', width: 150, features: { sortable: true } },
    12. { code: 'confirmed', name: '常住人口', width: 100, features: { sortable: true } },
    13. { code: 'flow', name: '流动人口', width: 100, features: { sortable: true } },
    14. { code: 'add', name: '新增人口', width: 100, features: { sortable: true } },
    15. { code: 't', name: '最后更新时间', width: 180 },
    16. ];
    17. function App() {
    18. // const pipeline = useTablePipeline({ components: { Table } })
    19. const pipeline = useTablePipeline()
    20. .input({ dataSource, columns })
    21. .use(
    22. features.sort({
    23. mode: 'single',
    24. // 默认排序的列
    25. defaultSorts: [{ code: 'settled', order: 'desc' }],
    26. highlightColumnWhenActive: true,
    27. })
    28. )
    29. .use(
    30. features.columnResize({
    31. fallbackSize: 120,
    32. handleBackground: '#ddd',
    33. handleHoverBackground: '#aaa',
    34. handleActiveBackground: '#89bff7',
    35. }),
    36. )
    37. return (
    38. <div style={{ padding: 24 }}>
    39. <BaseTable {...pipeline.getProps()} />
    40. </div>
    41. );
    42. }
    43. export default App;
    44. // Table基本用法
    45. <BaseTable dataSource={dataSource} columns={columns} />