columnAlign.tsx 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import React from 'react';
  2. import { Table, Avatar, Space } from '../../../index';
  3. import { ColumnProps, Direction } from '../../../table/interface';
  4. export default function App(props: { direction?: Direction }) {
  5. const { direction } = props;
  6. const columns: ColumnProps[] = [
  7. {
  8. title: '标题 align left + fixed left',
  9. dataIndex: 'name',
  10. render: (text, record, index) => {
  11. return (
  12. <Space spacing={12}>
  13. <Avatar
  14. size="small"
  15. shape="square"
  16. src={record.nameIconSrc}
  17. ></Avatar>
  18. {text}
  19. </Space>
  20. );
  21. },
  22. align: 'left',
  23. fixed: 'left',
  24. width: 300
  25. },
  26. {
  27. title: '大小 align center',
  28. dataIndex: 'size',
  29. align: 'center',
  30. width: 200,
  31. },
  32. {
  33. title: '所有者 align right',
  34. dataIndex: 'owner',
  35. render: (text, record, index) => {
  36. return (
  37. <Space spacing={4}>
  38. <Avatar size="small" color={record.avatarBg}>
  39. {typeof text === 'string' && text.slice(0, 1)}
  40. </Avatar>
  41. {text}
  42. </Space>
  43. );
  44. },
  45. align: 'right',
  46. },
  47. {
  48. title: '更新日期 align default + fixed right',
  49. dataIndex: 'updateTime',
  50. width: 200,
  51. fixed: 'right',
  52. }
  53. ];
  54. const data = [
  55. {
  56. key: '1',
  57. name: 'Semi Design 设计稿.fig',
  58. nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/figma-icon.png',
  59. size: '2M',
  60. owner: '姜鹏志',
  61. updateTime: '2020-02-02 05:13',
  62. avatarBg: 'grey',
  63. },
  64. {
  65. key: '2',
  66. name: 'Semi Design 分享演示文稿',
  67. nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/docs-icon.png',
  68. size: '2M',
  69. owner: '郝宣',
  70. updateTime: '2020-01-17 05:31',
  71. avatarBg: 'red',
  72. },
  73. {
  74. key: '3',
  75. name: '设计文档',
  76. nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/docs-icon.png',
  77. size: '34KB',
  78. owner: 'Zoey Edwards',
  79. updateTime: '2020-01-26 11:01',
  80. avatarBg: 'light-blue',
  81. },
  82. ];
  83. return <Table direction={direction} bordered columns={columns} dataSource={data} scroll={{ y: 300, x: 1200 }} pagination={false} />;
  84. }