index.js 2.9 KB

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