index.jsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import React from 'react';
  2. import { Table, Tooltip, Tag } from '@douyinfe/semi-ui';
  3. App.storyName = 'fixed z-index bug';
  4. export default function App() {
  5. const columns = [
  6. {
  7. title: 'Name',
  8. dataIndex: 'name',
  9. width: 150,
  10. fixed: true,
  11. filters: [
  12. {
  13. text: 'King 3',
  14. value: 'King 3',
  15. },
  16. {
  17. text: 'King 4',
  18. value: 'King 4',
  19. },
  20. ],
  21. onFilter: (value, record) => record.name.includes(value),
  22. },
  23. {
  24. title: 'Age',
  25. dataIndex: 'age',
  26. width: 150,
  27. sorter: (a, b) => (a.age - b.age > 0 ? 1 : -1),
  28. },
  29. {
  30. title: 'Address',
  31. width: 200,
  32. dataIndex: 'address',
  33. },
  34. {
  35. title: 'Description',
  36. // width: 400,
  37. dataIndex: 'description',
  38. },
  39. {
  40. fixed: 'right',
  41. width: 250,
  42. render: (text, record) => <Tooltip content={record.description}><Tag color="green">Show Info</Tag></Tooltip>
  43. }
  44. ];
  45. let data = [];
  46. const rowSelection = {
  47. onChange: (selectedRowKeys, selectedRows) => {
  48. // console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
  49. },
  50. getCheckboxProps: record => ({
  51. disabled: record.name === 'Michael James', // Column configuration not to be checked
  52. name: record.name,
  53. }),
  54. // fixed: true,
  55. };
  56. for (let i = 0; i < 46; i++) {
  57. let age = (i * 1000) % 149;
  58. let name = `Edward King ${i}`;
  59. data.push({
  60. key: `${ i}`,
  61. name,
  62. age,
  63. address: `London, Park Lane no. ${i}`,
  64. description: `My name is ${name}, I am ${age} years old, living in New York No. ${i + 1} Lake Park.`,
  65. });
  66. }
  67. const scroll = { y: 300, x: 1500 };
  68. return (
  69. <div style={{ position: 'relative', height: '100vh' }}>
  70. <div style={{ height: 60, background: 'red', position: 'absolute', top: 0, left: 0, right: 0, zIndex: 2 }}>
  71. Fixed Header
  72. </div>
  73. <Table
  74. columns={columns}
  75. dataSource={data}
  76. scroll={scroll}
  77. rowSelection={rowSelection}
  78. />
  79. </div>
  80. );
  81. }