index.jsx 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 data = useMemo(() => {
  61. const data = [];
  62. for (let i = 0; i < 100; i++) {
  63. let age = (i * 1000) % 149 ;
  64. let name = `Edward King ${i}`;
  65. data.push({
  66. key: '' + i,
  67. company: {
  68. name: 'ByteDance',
  69. address: 'No. 48, Zhichun Road',
  70. },
  71. name,
  72. age,
  73. address: `London, Park Lane no. ${i}`,
  74. description: `My name is ${name}, I am ${age} years old, living in New York No. ${i + 1} Lake Park.`,
  75. });
  76. }
  77. return data;
  78. });
  79. return (
  80. <Table
  81. resizable={{
  82. onResize: (...args) => console.log(...args),
  83. }}
  84. rowSelection={{ fixed: true }}
  85. expandedRowRender={record => <article>{record.description}</article>}
  86. columns={columns}
  87. dataSource={data}
  88. scroll={{ x: '150%', y: 500 }}
  89. onChange={(...args) => console.log(...args)}
  90. />
  91. );
  92. }