RTLTable.jsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import React, { useMemo } from 'react';
  2. import { Table, Checkbox } from '@douyinfe/semi-ui';
  3. export default function RTLTable() {
  4. const sortColumns = useMemo(() => [
  5. {
  6. title: 'Name',
  7. dataIndex: 'name',
  8. filters: [
  9. {
  10. text: 'Joe',
  11. value: 'Joe',
  12. },
  13. {
  14. text: 'Jim',
  15. value: 'Jim',
  16. },
  17. {
  18. text: 'Submenu',
  19. value: 'Submenu',
  20. children: [
  21. {
  22. text: 'Green',
  23. value: 'Green',
  24. },
  25. {
  26. text: 'Black',
  27. value: 'Black',
  28. },
  29. ],
  30. },
  31. ],
  32. onFilter: (value, record) => record.name.indexOf(value) === 0,
  33. sorter: (a, b) => a.name.length - b.name.length,
  34. },
  35. {
  36. title: 'Age',
  37. dataIndex: 'age',
  38. defaultSortOrder: 'descend',
  39. sorter: (a, b) => a.age - b.age,
  40. },
  41. {
  42. title: 'Address',
  43. dataIndex: 'address',
  44. filters: [
  45. {
  46. text: 'London',
  47. value: 'London',
  48. },
  49. {
  50. text: 'New York',
  51. value: 'New York',
  52. },
  53. ],
  54. filterMultiple: false,
  55. onFilter: (value, record) => record.address.indexOf(value) === 0,
  56. sorter: (a, b) => a.address.length - b.address.length,
  57. },
  58. ], []);
  59. const sortData = useMemo(() => [
  60. {
  61. key: '1',
  62. name: 'John Brown',
  63. age: 32,
  64. address: 'New York No. 1 Lake Park',
  65. },
  66. {
  67. key: '2',
  68. name: 'Jim Green',
  69. age: 42,
  70. address: 'London No. 1 Lake Park',
  71. },
  72. {
  73. key: '3',
  74. name: 'Joe Black',
  75. age: 32,
  76. address: 'Sidney No. 1 Lake Park',
  77. },
  78. {
  79. key: '4',
  80. name: 'Jim Red',
  81. age: 32,
  82. address: 'London No. 2 Lake Park',
  83. },
  84. ], []);
  85. return (
  86. <>
  87. <Checkbox onChange={e => console.log(e)}>Semi Design</Checkbox>
  88. <Table columns={sortColumns} dataSource={sortData} />
  89. </>
  90. );
  91. }