index.jsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import React, { useMemo } from 'react';
  2. import { Table } from '@douyinfe/semi-ui';
  3. import { VariableSizeGrid as Grid } from 'react-window';
  4. const Demo = () => {
  5. const dataTotalSize = 100;
  6. const scroll = {
  7. x: 1200,
  8. y: 600,
  9. };
  10. const expandColumns = [
  11. {
  12. title: 'Name',
  13. dataIndex: 'name',
  14. width: 250,
  15. fixed: 'left',
  16. key: 'name',
  17. render: (text, record, index, { expandIcon: realExpandIcon }) => {
  18. return (
  19. <>
  20. {/* {record.description ? realExpandIcon : null} */}
  21. {text}
  22. </>
  23. );
  24. },
  25. },
  26. { title: 'Age', dataIndex: 'age', key: 'age', width: 200 },
  27. { title: 'Address', dataIndex: 'address', key: 'address' },
  28. {
  29. width: 200,
  30. title: 'Action',
  31. dataIndex: '',
  32. key: 'x',
  33. render: () => <a>Delete</a>,
  34. fixed: 'right',
  35. },
  36. ];
  37. const data = useMemo(() => {
  38. const _data = [];
  39. for (let i = 0; i < dataTotalSize; i++) {
  40. let age = (i * 1000) % 149 ;
  41. let name = `Edward King ${i}`;
  42. _data.push({
  43. key: '' + i,
  44. name,
  45. age,
  46. address: `London, Park Lane no. ${i} Lake Park`,
  47. description: `My name is ${name}, I am ${age} years old, living in New York No. ${i + 1} Lake Park.`,
  48. });
  49. }
  50. return _data;
  51. }, [dataTotalSize]);
  52. return (
  53. <Table
  54. style={{ width: 800 }}
  55. columns={expandColumns}
  56. // defaultExpandAllRows
  57. // rowKey={'kkk'}
  58. expandedRowRender={(record, index, expanded) => (
  59. <article style={{ margin: 0 }}>
  60. <p>
  61. {index}: {expanded ? 'expanded' : 'unexpanded'}
  62. </p>
  63. <p>{record.description}</p>
  64. </article>
  65. )}
  66. onExpand={(expanded, expandedRow, domEvent) => {
  67. domEvent && domEvent.stopPropagation();
  68. console.log(expanded, expandedRow, domEvent);
  69. }}
  70. onRow={(record, index) => {
  71. return {
  72. onClick: () => {
  73. console.log(`Row ${index} clicked: `, record);
  74. },
  75. };
  76. }}
  77. // hideExpandedColumn={false}
  78. expandCellFixed={true}
  79. dataSource={data}
  80. scroll={scroll}
  81. pagination={false}
  82. components={{
  83. body: {
  84. outer: 'div',
  85. wrapper: 'div',
  86. row: 'div',
  87. cell: 'div',
  88. colgroup: {
  89. wrapper: 'div',
  90. col: 'div',
  91. },
  92. },
  93. }}
  94. />
  95. );
  96. };
  97. export default Demo;