JSXColumnsNest.tsx 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import React, { useMemo } from 'react';
  2. import Table from '../index';
  3. import { DataType } from '../Table';
  4. const JSXColumnsNest: React.FunctionComponent = () => {
  5. const data = useMemo(() => {
  6. const _data = [];
  7. for (let i = 0; i < 100; i++) {
  8. const age = (i * 1000) % 149 ;
  9. const name = `Edward King ${i}`;
  10. _data.push({
  11. key: `${ i}`,
  12. company: {
  13. name: 'ByteDance',
  14. address: 'No. 48, Zhichun Road',
  15. },
  16. name,
  17. age,
  18. address: `No ${i + 1}, Zhongguancun Street`,
  19. description: `My name is ${name}, I am ${age} years old, living in No ${i + 1}, Zhongguancun Street`,
  20. });
  21. }
  22. return _data;
  23. }, []);
  24. return (
  25. <Table
  26. rowSelection={{ fixed: true }}
  27. expandedRowRender={(record: DataType): React.ReactNode => <article>{record.description}</article>}
  28. dataSource={data}
  29. scroll={{ x: '120%', y: 400 }}
  30. onChange={(...args: Array<unknown>): void => console.log(args)}
  31. >
  32. <Table.Column title={'Base Information'} fixed>
  33. <Table.Column
  34. title={'Name'}
  35. dataIndex={'name'}
  36. fixed
  37. width={200}
  38. filters={[
  39. {
  40. text: 'Code 45',
  41. value: '45',
  42. },
  43. {
  44. text: 'King 4',
  45. value: 'King 4',
  46. },
  47. ]}
  48. onFilter={(value, record): boolean => record.name.includes(value)}
  49. />
  50. {
  51. // 这样做是为了查看是否符合类型定义
  52. (Math.random() > 0.5) ? (
  53. <Table.Column
  54. title={'Age'}
  55. dataIndex={'age'}
  56. fixed
  57. width={100}
  58. sorter={(a: DataType, b: DataType): number => (a.age - b.age > 0 ? 1 : -1)}
  59. />
  60. ) : null
  61. }
  62. </Table.Column>
  63. <Table.Column title={'Company Information'}>
  64. <Table.Column title={'Company Name'} dataIndex={'company.name'} />
  65. <Table.Column title={'Company Address'} dataIndex={'company.address'} />
  66. </Table.Column>
  67. <Table.Column title={'Address'} width={250} fixed={'right'} dataIndex={'address'} />
  68. </Table>
  69. );
  70. };
  71. export default JSXColumnsNest;