index.jsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import React from 'react';
  2. import { Table, Tag, Tooltip } from '@douyinfe/semi-ui';
  3. export default class VirtualizedFixedDemo 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. filters: [
  13. {
  14. text: 'Code 45',
  15. value: '45',
  16. },
  17. {
  18. text: 'King 4',
  19. value: 'King 4',
  20. },
  21. ],
  22. onFilter: (value, record) => record.name.includes(value),
  23. },
  24. {
  25. title: 'Age',
  26. dataIndex: 'age',
  27. width: 150,
  28. sorter: (a, b) => (a.age - b.age > 0 ? 1 : -1),
  29. },
  30. {
  31. title: 'Address',
  32. // width: 200,
  33. dataIndex: 'address',
  34. onCell: (record,index) => {
  35. return {
  36. style:{ color:'red'},
  37. className: 'test-red'
  38. }
  39. }
  40. },
  41. {
  42. fixed: 'right',
  43. width: 250,
  44. render: (text, record) => (
  45. <Tooltip content={record.description}>
  46. <Tag color="green">Show Info</Tag>
  47. </Tooltip>
  48. ),
  49. },
  50. ];
  51. this.data = [];
  52. for (let i = 0; i < 1000; i++) {
  53. let age = (i * 1000) % 149 ;
  54. let name = `Edward King ${i}`;
  55. this.data.push({
  56. key: '' + i,
  57. name,
  58. age,
  59. address: `London, Park Lane no. ${i}`,
  60. description: `My name is ${name}, I am ${age} years old, living in New York No. ${i + 1} Lake Park.`,
  61. });
  62. }
  63. this.scroll = { y: 400, x: 800 };
  64. this.style = { width: 750, margin: '0 auto' };
  65. }
  66. render() {
  67. return (
  68. <Table
  69. pagination={false}
  70. columns={this.columns}
  71. dataSource={this.data}
  72. scroll={this.scroll}
  73. style={this.style}
  74. virtualized
  75. />
  76. );
  77. }
  78. }