index.jsx 2.8 KB

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