rowSelection.jsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import React from 'react';
  2. import { Table, Avatar } from '@douyinfe/semi-ui';
  3. import { IconMore } from '@douyinfe/semi-icons';
  4. function App() {
  5. const columns = [
  6. {
  7. title: '标题',
  8. dataIndex: 'name',
  9. width: 400,
  10. render: (text, record, index) => {
  11. return (
  12. <div>
  13. <Avatar size="small" shape="square" src={record.nameIconSrc} style={{ marginRight: 12 }}></Avatar>
  14. {text}
  15. </div>
  16. );
  17. }
  18. },
  19. {
  20. title: '大小',
  21. dataIndex: 'size',
  22. },
  23. {
  24. title: '所有者',
  25. dataIndex: 'owner',
  26. render: (text, record, index) => {
  27. return (
  28. <div>
  29. <Avatar size="small" color={record.avatarBg} style={{ marginRight: 4 }}>{typeof text === 'string' && text.slice(0, 1)}</Avatar>
  30. {text}
  31. </div>
  32. );
  33. }
  34. },
  35. {
  36. title: '更新日期',
  37. dataIndex: 'updateTime',
  38. },
  39. {
  40. title: '',
  41. dataIndex: 'operate',
  42. render: () => {
  43. return <IconMore />;
  44. }
  45. },
  46. ];
  47. const data = [
  48. {
  49. key: '1',
  50. name: 'Semi Design 设计稿.fig',
  51. nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/figma-icon.png',
  52. size: '2M',
  53. owner: '姜鹏志',
  54. updateTime: '2020-02-02 05:13',
  55. avatarBg: 'grey'
  56. },
  57. {
  58. key: '2',
  59. name: 'Semi Design 分享演示文稿',
  60. nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/docs-icon.png',
  61. size: '2M',
  62. owner: '郝宣',
  63. updateTime: '2020-01-17 05:31',
  64. avatarBg: 'red'
  65. },
  66. {
  67. key: '3',
  68. name: '设计文档',
  69. nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/docs-icon.png',
  70. size: '34KB',
  71. owner: 'Zoey Edwards',
  72. updateTime: '2020-01-26 11:01',
  73. avatarBg: 'light-blue'
  74. },
  75. {
  76. key: '4',
  77. name: 'Semi Pro 设计稿.fig',
  78. nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/figma-icon.png',
  79. size: '2M',
  80. owner: '姜鹏志',
  81. updateTime: '2020-02-02 05:13',
  82. avatarBg: 'grey'
  83. },
  84. {
  85. key: '5',
  86. name: 'Semi Pro 分享演示文稿',
  87. nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/docs-icon.png',
  88. size: '2M',
  89. owner: '郝宣',
  90. updateTime: '2020-01-17 05:31',
  91. avatarBg: 'red'
  92. },
  93. {
  94. key: '6',
  95. name: 'Semi Pro 设计文档',
  96. nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/docs-icon.png',
  97. size: '34KB',
  98. owner: 'Zoey Edwards',
  99. updateTime: '2020-01-26 11:01',
  100. avatarBg: 'light-blue'
  101. },
  102. ];
  103. const rowSelection = {
  104. getCheckboxProps: record => ({
  105. disabled: record.name === '设计文档', // Column configuration not to be checked
  106. name: record.name,
  107. }),
  108. onSelect: (record, selected) => {
  109. console.log(`select row: ${selected}`, record);
  110. },
  111. onSelectAll: (selected, selectedRows) => {
  112. console.log(`select all rows: ${selected}`, selectedRows);
  113. },
  114. onChange: (selectedRowKeys, selectedRows) => {
  115. console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
  116. },
  117. };
  118. const pagination = useMemo(() => ({
  119. pageSize: 3
  120. }), []);
  121. return <Table columns={columns} dataSource={data} rowSelection={rowSelection} pagination={pagination} />;
  122. }
  123. render(App);