index.jsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import React, { useMemo } from 'react';
  2. import { Table } from '../../../index';
  3. export default function Demo() {
  4. const columns = [
  5. {
  6. title: 'Base Information',
  7. fixed: 'left',
  8. children: [
  9. {
  10. title: 'Name',
  11. dataIndex: 'name',
  12. fixed: 'left',
  13. width: 200,
  14. filters: [
  15. {
  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: 'left',
  34. width: 100,
  35. sorter: (a, b) => (a.age - b.age > 0 ? 1 : -1),
  36. },
  37. ],
  38. },
  39. {
  40. title: 'Company Information',
  41. children: [
  42. {
  43. title: 'Company Name',
  44. dataIndex: 'company.name',
  45. width: 200,
  46. },
  47. {
  48. title: 'Company Address',
  49. dataIndex: 'company.address',
  50. },
  51. ],
  52. },
  53. {
  54. title: 'Address',
  55. width: 250,
  56. dataIndex: 'address',
  57. fixed: 'right',
  58. },
  59. ];
  60. const total = 1000;
  61. const data = useMemo(() => {
  62. const data = [];
  63. for (let i = 0; i < total; i++) {
  64. let age = (i * 1000) % 149 ;
  65. let name = `Edward King ${i}`;
  66. data.push({
  67. key: 'row' + i,
  68. company: {
  69. name: 'ByteDance',
  70. address: 'No. 48, Zhichun Road',
  71. },
  72. name,
  73. age,
  74. address: `London, Park Lane no. ${i}`,
  75. description: `My name is ${name}, I am ${age} years old, living in New York No. ${i + 1} Lake Park.`,
  76. });
  77. }
  78. return data;
  79. }, [total]);
  80. return (
  81. <Table
  82. // resizable={{
  83. // onResize: (...args) => console.log(...args),
  84. // }}
  85. rowSelection={{ fixed: true }}
  86. // expandedRowRender={record => (
  87. // <article>
  88. // {record.description}
  89. // {record.description}
  90. // {record.description}
  91. // {record.description}
  92. // {record.description}
  93. // </article>
  94. // )}
  95. columns={columns}
  96. dataSource={data}
  97. groupBy={'age'}
  98. renderGroupSection={(groupKey, group) => <span>Age: {groupKey}</span>}
  99. clickGroupedRowToExpand
  100. style={{ width: 800 }}
  101. scroll={{ x: '150%', y: 600 }}
  102. onChange={(...args) => console.log(...args)}
  103. virtualized
  104. pagination={false}
  105. />
  106. );
  107. }