resizable copy.jsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import React, { useMemo } from 'react';
  2. import { Table, Avatar } from '@douyinfe/semi-ui';
  3. const DAY = 24 * 60 * 60 * 1000;
  4. const figmaIconUrl = 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/figma-icon.png';
  5. const pagination = { pageSize: 5 };
  6. function ResizableDemo() {
  7. const columns = [
  8. {
  9. title: '标题',
  10. dataIndex: 'name',
  11. width: 400,
  12. render: (text, record, index) => {
  13. return (
  14. <div>
  15. <Avatar size="small" shape="square" src={figmaIconUrl} style={{ marginRight: 12 }}></Avatar>
  16. {text}
  17. </div>
  18. );
  19. },
  20. filters: [
  21. {
  22. text: 'Semi Design 设计稿',
  23. value: 'Semi Design 设计稿',
  24. },
  25. {
  26. text: 'Semi Pro 设计稿',
  27. value: 'Semi Pro 设计稿',
  28. },
  29. ],
  30. onFilter: (value, record) => record.name.includes(value),
  31. },
  32. {
  33. title: '大小',
  34. dataIndex: 'size',
  35. width: 200,
  36. sorter: (a, b) => a.size - b.size > 0 ? 1 : -1,
  37. render: (text) => `${text} KB`
  38. },
  39. {
  40. title: '所有者',
  41. width: 200,
  42. dataIndex: 'owner',
  43. render: (text, record, index) => {
  44. return (
  45. <div>
  46. <Avatar size="small" color={record.avatarBg} style={{ marginRight: 4 }}>{typeof text === 'string' && text.slice(0, 1)}</Avatar>
  47. {text}
  48. </div>
  49. );
  50. }
  51. },
  52. {
  53. title: '更新日期',
  54. dataIndex: 'updateTime',
  55. sorter: (a, b) => a.updateTime - b.updateTime > 0 ? 1 : -1,
  56. render: (value) => {
  57. return dateFns.format(new Date(value), 'yyyy-MM-dd');
  58. }
  59. }
  60. ];
  61. const data = useMemo(() => {
  62. const _data = [];
  63. for (let i = 0; i < 46; i++) {
  64. const isSemiDesign = i % 2 === 0;
  65. const randomNumber = (i * 1000) % 199;
  66. _data.push({
  67. key: '' + i,
  68. name: isSemiDesign ? `Semi Design 设计稿${i}.fig` : `Semi Pro 设计稿${i}.fig`,
  69. owner: isSemiDesign ? '姜鹏志' : '郝宣',
  70. size: randomNumber,
  71. updateTime: new Date().valueOf() + randomNumber * DAY,
  72. avatarBg: isSemiDesign ? 'grey' : 'red'
  73. });
  74. }
  75. return _data;
  76. }, []);
  77. const resizable = {
  78. onResizeStart: curColumn => {
  79. const className = addClass(curColumn.className, 'my-resizing');
  80. return { className };
  81. },
  82. onResizeStop: curColumn => {
  83. const className = removeClass(curColumn.className, 'my-resizing');
  84. return { className };
  85. }
  86. };
  87. return (
  88. <div id="components-table-demo-resizable-column">
  89. <Table columns={columns} dataSource={data} resizable={resizable} pagination={pagination} bordered />
  90. </div>
  91. );
  92. }
  93. render(ResizableDemo);