FixedVirtualizedEmpty.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import React, { useState } from 'react';
  2. import { Table, Tag, Tooltip, Button } from '../../../index';
  3. export default function App() {
  4. const [data, setData] = useState([]);
  5. const loadData = () => {
  6. if (Array.isArray(data) && data.length > 0) {
  7. setData([]);
  8. return;
  9. }
  10. const newData = [];
  11. for (let i = 0; i < 10000; i++) {
  12. const age = (i * 1000) % 149;
  13. const name = `Edward King ${i}`;
  14. newData.push({
  15. key: '' + i,
  16. name,
  17. age,
  18. address: `London, Park Lane no. ${i}`,
  19. description: `My name is ${name}, I am ${age} years old, living in New York No. ${i + 1} Lake Park.`,
  20. });
  21. }
  22. setData(newData);
  23. };
  24. const scroll = { y: 600, x: 1600 };
  25. const style = { width: 800 };
  26. const columns = [
  27. {
  28. title: 'Name',
  29. dataIndex: 'name',
  30. width: 150,
  31. fixed: true,
  32. filters: [
  33. {
  34. text: 'Code 45',
  35. value: '45',
  36. },
  37. {
  38. text: 'King 4',
  39. value: 'King 4',
  40. },
  41. ],
  42. onFilter: (value, record) => record.name.includes(value),
  43. },
  44. {
  45. title: 'Age',
  46. dataIndex: 'age',
  47. width: 150,
  48. sorter: (a, b) => (a.age - b.age > 0 ? 1 : -1),
  49. },
  50. {
  51. title: 'Address',
  52. // width: 200,
  53. dataIndex: 'address',
  54. },
  55. {
  56. fixed: 'right' as const,
  57. width: 250,
  58. render: (text, record) => (
  59. <Tooltip content={record.description}>
  60. <Tag color="green">Show Info</Tag>
  61. </Tooltip>
  62. ),
  63. },
  64. ];
  65. return (
  66. <div>
  67. <Button onClick={loadData}>load data</Button>
  68. <Table pagination={false} columns={columns} dataSource={data} scroll={scroll} style={style} virtualized />
  69. </div>
  70. );
  71. }