index.jsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import React from 'react';
  2. import { Table, Tooltip, Tag } from '@douyinfe/semi-ui';
  3. export default class ResizableDemo extends React.Component {
  4. constructor() {
  5. super();
  6. this.columns = [
  7. {
  8. title: 'Name',
  9. dataIndex: 'name',
  10. width: 150,
  11. filters: [
  12. {
  13. text: 'King 3',
  14. value: 'King 3',
  15. },
  16. {
  17. text: 'King 4',
  18. value: 'King 4',
  19. },
  20. ],
  21. onFilter: (value, record) => record.name.includes(value),
  22. },
  23. {
  24. title: 'Age',
  25. dataIndex: 'age',
  26. width: 150,
  27. sorter: (a, b) => (a.age - b.age > 0 ? 1 : -1),
  28. },
  29. {
  30. title: 'Address',
  31. width: 200,
  32. dataIndex: 'address',
  33. },
  34. {
  35. render: (text, record) => (
  36. <Tooltip content={record.description}><Tag color="green">Show Info</Tag></Tooltip>
  37. )
  38. }
  39. ];
  40. this.state = {
  41. selectedRowKeys: []
  42. };
  43. this.data = [];
  44. this.rowSelection = {
  45. onChange: (selectedRowKeys, selectedRows) => {
  46. // console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
  47. this.setState({ selectedRowKeys });
  48. },
  49. getCheckboxProps: record => ({
  50. disabled: record.name === 'Michael James', // Column configuration not to be checked
  51. name: record.name,
  52. }),
  53. };
  54. for (let i = 0; i < 46; i++) {
  55. let age = (i * 1000) % 149 ;
  56. let name = `Edward King ${i}`;
  57. this.data.push({
  58. key: `${ i}`,
  59. name,
  60. age,
  61. address: `London, Park Lane no. ${i}`,
  62. description: `My name is ${name}, I am ${age} years old, living in New York No. ${i + 1} Lake Park.`,
  63. });
  64. }
  65. }
  66. render() {
  67. const { selectedRowKeys } = this.state;
  68. return (
  69. <Table
  70. columns={this.columns}
  71. dataSource={this.data}
  72. rowSelection={{
  73. ...this.rowSelection,
  74. selectedRowKeys,
  75. }}
  76. resizable
  77. bordered
  78. />
  79. );
  80. }
  81. }