index.jsx 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import React, { useMemo } from 'react';
  2. import { Table, Button } from '@douyinfe/semi-ui';
  3. Demo.storyName = "fixed jsx column nested bug";
  4. /**
  5. * fixed https://github.com/DouyinFE/semi-design/issues/619
  6. *
  7. * Test with Cypress
  8. */
  9. export default function Demo() {
  10. const columns = [
  11. {
  12. title: 'Base Information',
  13. fixed: 'left',
  14. children: [
  15. {
  16. title: 'Name',
  17. dataIndex: 'name',
  18. width: 200,
  19. },
  20. {
  21. title: 'Age',
  22. dataIndex: 'age',
  23. width: 100,
  24. },
  25. ],
  26. },
  27. {
  28. title: 'Company Information',
  29. children: [
  30. {
  31. title: 'Company Name',
  32. dataIndex: 'company.name',
  33. },
  34. {
  35. title: 'Company Address',
  36. dataIndex: 'company.address',
  37. },
  38. ],
  39. }
  40. ];
  41. const data = useMemo(() => {
  42. const data = [];
  43. for (let i = 0; i < 100; i++) {
  44. let age = (i * 1000) % 149;
  45. let name = `Edward King ${i}`;
  46. data.push({
  47. key: '' + i,
  48. company: {
  49. name: 'ByteDance',
  50. address: 'No. 48, Zhichun Road',
  51. },
  52. name,
  53. age,
  54. address: `No ${i + 1}, Zhongguancun Street`,
  55. description: `My name is ${name}, I am ${age} years old, living in No ${i + 1}, Zhongguancun Street`,
  56. });
  57. }
  58. return data;
  59. }, []);
  60. const [flag, setFlag] = React.useState(true);
  61. return (
  62. <>
  63. <Button data-cy="button" onClick={()=> setFlag(!flag)}>reRender</Button>
  64. <Table dataSource={data} pagination={true} size="small">
  65. {columns.map((item, titleIndex) =>
  66. (
  67. <Table.Column
  68. key={titleIndex}
  69. title={item.title}
  70. >
  71. {item.children.map(
  72. (childItem, columnIndex) =>
  73. (
  74. <Table.Column
  75. title={childItem.title}
  76. dataIndex={childItem.dataIndex}
  77. key={titleIndex.toString() + columnIndex.toString()}
  78. />
  79. )
  80. )}
  81. </Table.Column>
  82. )
  83. )}
  84. <Table.Column
  85. title=""
  86. key="lastColumn"
  87. render={() => 123}
  88. />
  89. </Table>
  90. </>
  91. );
  92. }