index.jsx 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import React, { useState, useEffect } from 'react';
  2. import Table from '../../index';
  3. function Demo() {
  4. const rowKey = record => `${record.city && record.city.toLowerCase()}-${record.job && record.job.toLowerCase()}`;
  5. const [data, setData] = useState([]);
  6. useEffect(() => {
  7. /**
  8. * FE => frontend engineer
  9. * BE => backend engineer
  10. * Andoird => android engineer
  11. * IOS => ios engineer
  12. * SE => software engineer
  13. */
  14. const data = [
  15. { city: 'Beijing', job: 'FE', department: 'IES' },
  16. { city: 'Beijing', job: 'BE', department: 'IES' },
  17. { city: 'Shanghai', job: 'Android', department: 'IES' },
  18. { city: 'Tokyo', job: 'Android', department: 'IES' },
  19. { city: 'Shanghai', job: 'IOS', department: 'EE' },
  20. { city: 'LA', job: 'SE', department: 'EE' },
  21. { city: 'Beijing', job: 'Android', department: 'EE' },
  22. { city: 'Tokyo', job: 'IOS', department: 'EE' },
  23. { city: 'Tokyo', job: 'SE', department: 'DATA' },
  24. { city: 'Shanghai', job: 'BE', department: 'DATA' },
  25. { city: 'LA', job: 'Android', department: 'DATA' },
  26. { city: 'LA', job: 'IOS', department: 'DATA' },
  27. ];
  28. setData(data);
  29. }, []);
  30. const columns = [
  31. { dataIndex: 'city', title: 'City', width: 200, sorter: (a, b) => (a.city > b.city ? 1 : -1), fixed: 'left' },
  32. {
  33. dataIndex: 'job',
  34. title: 'Job',
  35. filters: [{ text: 'IOS', value: 'IOS' }, { text: 'Android', value: 'Android' }],
  36. onFilter: (value, record) => record.job && record.job.indexOf(value) === 0,
  37. },
  38. { dataIndex: 'department', title: 'Department', fixed: 'right', width: 200 },
  39. ];
  40. return (
  41. <div style={{ padding: '20px 0px', width: 600 }}>
  42. <Table
  43. dataSource={data}
  44. rowKey={rowKey}
  45. groupBy={'city'}
  46. columns={columns}
  47. renderGroupSection={groupKey => (
  48. <strong>
  49. Jobs in {groupKey} Jobs in {groupKey}:Jobs in {groupKey}:Jobs in {groupKey}:Jobs in {groupKey}
  50. :Jobs in {groupKey}:Jobs in {groupKey}:Jobs in {groupKey}:Jobs in {groupKey}:Jobs in {groupKey}
  51. :Jobs in {groupKey}:Jobs in {groupKey}:{/* Jobs in {groupKey}: */}
  52. </strong>
  53. )}
  54. onGroupedRow={(group, index) => {
  55. return {
  56. // onMouseEnter: () => {
  57. // console.log(`Grouped row mouse enter: `, group, index);
  58. // },
  59. // onMouseLeave: () => {
  60. // console.log(`Grouped row mouse leave: `, group, index);
  61. // },
  62. onClick: () => {
  63. console.log(`Grouped row mouse click: `, group, index);
  64. },
  65. };
  66. }}
  67. // bordered
  68. defaultExpandAllRows
  69. clickGroupedRowToExpand
  70. scroll={{ y: 480, x: 2000 }}
  71. />
  72. </div>
  73. );
  74. }
  75. export default Demo;