Skip to content

Commit ebf2851

Browse files
committed
demo: demo add getContainerWidth
1 parent 1297e09 commit ebf2851

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

docs/examples/column-resize.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useState } from 'react';
2-
import Table from 'rc-table';
2+
import Table, { INTERNAL_HOOKS } from 'rc-table';
33
import type { ColumnType } from 'rc-table';
44
import '../../assets/index.less';
55

@@ -63,6 +63,15 @@ const Demo = () => {
6363
return result;
6464
});
6565
}}
66+
internalHooks={INTERNAL_HOOKS}
67+
getContainerWidth={(ele, width) => {
68+
// Minus border
69+
const borderWidth = getComputedStyle(
70+
ele.querySelector('.rc-table-body'),
71+
).borderInlineStartWidth;
72+
const mergedWidth = width - parseInt(borderWidth, 10);
73+
return mergedWidth;
74+
}}
6675
/>
6776
<br />
6877
大多数情况
@@ -80,6 +89,15 @@ const Demo = () => {
8089
return result;
8190
});
8291
}}
92+
internalHooks={INTERNAL_HOOKS}
93+
getContainerWidth={(ele, width) => {
94+
// Minus border
95+
const borderWidth = getComputedStyle(
96+
ele.querySelector('.rc-table-body'),
97+
).borderInlineStartWidth;
98+
const mergedWidth = width - parseInt(borderWidth, 10);
99+
return mergedWidth;
100+
}}
83101
/>
84102
{/* <Table resizable style={{ width: 800 }} columns={columns} data={data} /> */}
85103
</div>

src/Header/useCellResize.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ export default function useCelResize(
6363
// If there is no column on the right, it will be allocated to the column on the left.
6464
let addWidthColumnKey: React.Key;
6565
const isDecreasingWidth = oldWidth - newWidth > 0;
66-
console.log('smallThanWidth', smallThanWidth);
6766
if (smallThanWidth > 0 && isDecreasingWidth) {
6867
const index = colsKeys.findIndex(key => key === columnKey);
6968
addWidthColumnKey = colsKeys[index + 1] ?? colsKeys[index - 1];

0 commit comments

Comments
 (0)