index.js 3.1 KB

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