index.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import React, { useMemo, useCallback } from 'react';
  2. import { Table, Tag, Tooltip } from '../../../index';
  3. class VirtualizedFixedDemo extends React.Component {
  4. constructor(props = {}) {
  5. super(props);
  6. this.virtualizedListRef = React.createRef();
  7. this.columns = [
  8. {
  9. title: 'Name',
  10. dataIndex: 'name',
  11. width: 150,
  12. fixed: true,
  13. filters: [
  14. {
  15. text: 'Code 45',
  16. value: '45',
  17. },
  18. {
  19. text: 'King 4',
  20. value: 'King 4',
  21. },
  22. ],
  23. onFilter: (value, record) => record.name.includes(value),
  24. },
  25. {
  26. title: 'Age',
  27. dataIndex: 'age',
  28. width: 150,
  29. sorter: (a, b) => (a.age - b.age > 0 ? 1 : -1),
  30. },
  31. {
  32. title: 'Address',
  33. // width: 200,
  34. dataIndex: 'address',
  35. },
  36. {
  37. fixed: 'right',
  38. width: 250,
  39. render: (text, record) => (
  40. <Tooltip content={record.description}>
  41. <Tag color="green">Show Info</Tag>
  42. </Tooltip>
  43. ),
  44. },
  45. ];
  46. this.data = [];
  47. this.rowSelection = {
  48. fixed: true,
  49. };
  50. for (let i = 0; i < 10000; i++) {
  51. let age = (i * 1000) % 149 ;
  52. let name = `Edward King ${i}`;
  53. this.data.push({
  54. key: '' + i,
  55. name,
  56. age,
  57. address: `London, Park Lane no. ${i}`,
  58. description: `My name is ${name}, I am ${age} years old, living in New York No. ${i + 1} Lake Park.`,
  59. });
  60. }
  61. this.scroll = { y: 600, x: 1600, scrollToFirstRowOnChange: true };
  62. this.style = { width: 800 };
  63. }
  64. render() {
  65. return (
  66. <>
  67. <div onClick={() => this.virtualizedListRef.current.scrollToItem(100)}>
  68. scroll to 100
  69. </div>
  70. <Table
  71. size={'small'}
  72. pagination={false}
  73. columns={this.columns}
  74. dataSource={this.data}
  75. scroll={this.scroll}
  76. style={this.style}
  77. rowSelection={this.rowSelection}
  78. virtualized
  79. getVirtualizedListRef={ref => this.virtualizedListRef = ref}
  80. />
  81. </>
  82. );
  83. }
  84. }
  85. export default VirtualizedFixedDemo;