Skip to content

Commit c0ca3e2

Browse files
committed
fix: stabilize column resize
1 parent 5781c2b commit c0ca3e2

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/dashboard/Data/Views/Views.react.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ class Views extends TableView {
159159
content = (
160160
<div className={tableStyles.rows}>
161161
<table style={{ width: this.state.tableWidth, tableLayout: 'fixed' }}>
162+
{this.renderColGroup()}
162163
<tbody>{data.map(row => this.renderRow(row))}</tbody>
163164
</table>
164165
{footer}
@@ -212,7 +213,7 @@ class Views extends TableView {
212213
content = String(value);
213214
}
214215
return (
215-
<td key={name} className={styles.cell} style={{ width }}>
216+
<td key={name} className={styles.cell}>
216217
{content}
217218
</td>
218219
);
@@ -221,13 +222,25 @@ class Views extends TableView {
221222
);
222223
}
223224

225+
renderColGroup() {
226+
return (
227+
<colgroup>
228+
{this.state.order.map(({ width }, i) => (
229+
<col key={i} style={{ width }} />
230+
))}
231+
</colgroup>
232+
);
233+
}
234+
224235
handleResize(index, delta) {
225-
this.setState(({ order, tableWidth }) => {
236+
this.setState(({ order }) => {
226237
const newOrder = [...order];
227-
const next = Math.max(40, newOrder[index].width + delta);
228-
const diff = next - newOrder[index].width;
229-
newOrder[index] = { ...newOrder[index], width: next };
230-
return { order: newOrder, tableWidth: tableWidth + diff };
238+
newOrder[index] = {
239+
...newOrder[index],
240+
width: Math.max(40, newOrder[index].width + delta),
241+
};
242+
const tableWidth = newOrder.reduce((sum, col) => sum + col.width, 0);
243+
return { order: newOrder, tableWidth };
231244
});
232245
}
233246

0 commit comments

Comments
 (0)