index.jsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { Table, Tooltip, Popconfirm, Popover, Tag } from '@douyinfe/semi-ui/';
  2. import React, { useMemo } from 'react';
  3. function EventTable(props = {}) {
  4. const dataTotalSize = 46;
  5. const columns = useMemo(
  6. () => [
  7. {
  8. title: 'Name',
  9. dataIndex: 'name',
  10. width: 150,
  11. },
  12. {
  13. title: 'Age',
  14. dataIndex: 'age',
  15. width: 150,
  16. },
  17. {
  18. title: 'Address',
  19. dataIndex: 'address',
  20. },
  21. {
  22. render: (text, record) => (
  23. <Popconfirm content={record.description}>
  24. <Tag color="green" onClick={e => console.log('tag clicked')}>
  25. Show Info
  26. </Tag>
  27. </Popconfirm>
  28. ),
  29. width: 150,
  30. },
  31. ],
  32. []
  33. );
  34. const data = useMemo(() => {
  35. const _data = [];
  36. for (let i = 0; i < dataTotalSize; i++) {
  37. let age = (i * 1000) % 149 ;
  38. let name = `Edward King ${i}`;
  39. _data.push({
  40. key: '' + i,
  41. name,
  42. age,
  43. address: `London, Park Lane no. ${i} Lake Park`,
  44. description: `My name is ${name}, I am ${age} years old, living in New York No. ${i + 1} Lake Park.`,
  45. });
  46. }
  47. return _data;
  48. }, []);
  49. const onRow = (record, index) => {
  50. const props = {};
  51. return {
  52. onClick: () => {
  53. console.log('row clicked');
  54. },
  55. className: index === 2 ? 'my-tr-class' : '',
  56. };
  57. };
  58. const onHeaderRow = useMemo(
  59. () => (columns, index) => {
  60. return {
  61. onMouseEnter: e => console.log('mouse enter: ', columns, index),
  62. onMouseLeave: e => console.log('mouse leave: ', columns, index),
  63. };
  64. },
  65. []
  66. );
  67. return <Table columns={columns} dataSource={data} onRow={onRow} onHeaderRow={onHeaderRow} />;
  68. }
  69. export default EventTable;