Skip to content

Commit a634e97

Browse files
authored
feat: Stabilize interactive table height to prevent notebook layout shifts (#2378)
This update introduces a new feature in the interactive table display that prevents notebook layout shifts when changing the number of rows per page. The table height is now intelligently set and fixed after its initial display, creating a more stable and predictable user experience. Verified at: vs code notebook: https://screencast.googleplex.com/cast/NTY2NjM1NDQwNDI2MTg4OHwzNDEwZTA5Zi0wOA Fixes #<460861785> 🦕
1 parent 798af4a commit a634e97

File tree

3 files changed

+468
-128
lines changed

3 files changed

+468
-128
lines changed

bigframes/display/table_widget.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,27 @@ function render({ model, el }) {
170170
model.save_changes();
171171
}
172172

173+
let isHeightInitialized = false;
174+
173175
function handleTableHTMLChange() {
174176
tableContainer.innerHTML = model.get(ModelProperty.TABLE_HTML);
175177

178+
// After the first render, dynamically set the container height to fit the
179+
// initial page (usually 10 rows) and then lock it.
180+
setTimeout(() => {
181+
if (!isHeightInitialized) {
182+
const table = tableContainer.querySelector('table');
183+
if (table) {
184+
const tableHeight = table.offsetHeight;
185+
// Add a small buffer(e.g. 2px) for borders to avoid scrollbars.
186+
if (tableHeight > 0) {
187+
tableContainer.style.height = `${tableHeight + 2}px`;
188+
isHeightInitialized = true;
189+
}
190+
}
191+
}
192+
}, 0);
193+
176194
const sortableColumns = model.get(ModelProperty.ORDERABLE_COLUMNS);
177195
const currentSortContext = model.get(ModelProperty.SORT_CONTEXT) || [];
178196

0 commit comments

Comments
 (0)