index.jsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import React from 'react';
  2. import { Table } from '@douyinfe/semi-ui';
  3. const Demo = () => {
  4. const expandColumns = [
  5. {
  6. title: 'Name',
  7. dataIndex: 'name',
  8. width: 250,
  9. fixed: 'left',
  10. key: 'name',
  11. render: (text, record, index, { expandIcon: realExpandIcon }) => (
  12. <>
  13. {/* {record.description ? realExpandIcon : null} */}
  14. {text}
  15. </>
  16. ),
  17. },
  18. { title: 'Age', dataIndex: 'age', key: 'age', width: 200 },
  19. { title: 'Address', dataIndex: 'address', key: 'address' },
  20. {
  21. width: 200,
  22. title: 'Action',
  23. dataIndex: '',
  24. key: 'x',
  25. render: () => <a>Delete</a>,
  26. fixed: 'right',
  27. },
  28. ];
  29. const expandData = [
  30. {
  31. key: 1,
  32. name: 'John Brown',
  33. age: 32,
  34. address: 'New York No. 1 Lake Park',
  35. description: 'My name is John Brown, I am 32 years old, living in New York No. 1 Lake Park.',
  36. },
  37. {
  38. key: 2,
  39. name: 'Jim Green',
  40. age: 42,
  41. address: 'London No. 1 Lake Park',
  42. // description: 'My name is Jim Green, I am 42 years old, living in London No. 1 Lake Park.',
  43. },
  44. {
  45. key: 3,
  46. name: 'Joe Black',
  47. age: 32,
  48. address: 'Sidney No. 1 Lake Park',
  49. description: 'My name is Joe Black, I am 32 years old, living in Sidney No. 1 Lake Park.',
  50. },
  51. ];
  52. return (
  53. <Table
  54. columns={expandColumns}
  55. // defaultExpandAllRows
  56. // rowKey={'kkk'}
  57. expandedRowRender={(record, index, expanded) => (
  58. <article style={{ margin: 0 }}>
  59. <p>
  60. {index}: {expanded ? 'expanded' : 'unexpanded'}
  61. </p>
  62. <p>{record.description}</p>
  63. </article>
  64. )}
  65. onExpand={(expanded, expandedRow, domEvent) => {
  66. domEvent && domEvent.stopPropagation();
  67. console.log(expanded, expandedRow, domEvent);
  68. }}
  69. onRow={(record, index) => ({
  70. onClick: () => {
  71. console.log(`Row ${index} clicked: `, record);
  72. },
  73. })}
  74. hideExpandedColumn={false}
  75. expandCellFixed={true}
  76. dataSource={expandData}
  77. scroll={{ x: '160%' }}
  78. />
  79. );
  80. };
  81. export default Demo;