Commit 1f7e35e417 for handsontable.com
commit 1f7e35e4176a8180c2e9051487202a1add21ff3c
Author: Szymon Dolnik <42141039+Haxikowy@users.noreply.github.com>
Date: Mon May 18 10:30:41 2026 +0200
DEV-1711: Fix page scroll when dataProvider loads data into an empty grid (#12591)
* DEV-1711: Fix page scroll when dataProvider loads data into an empty grid
* DEV-1711: Add changelog entry for PR #12591
diff --git a/.changelogs/12591.json b/.changelogs/12591.json
new file mode 100644
index 0000000000..1aba333e7f
--- /dev/null
+++ b/.changelogs/12591.json
@@ -0,0 +1,8 @@
+{
+ "issuesOrigin": "public",
+ "title": "Fixed the browser page scrolling to the grid when `dataProvider` loads rows for the first time into an empty grid with `emptyDataState` enabled.",
+ "type": "fixed",
+ "issueOrPR": 12591,
+ "breaking": false,
+ "framework": "none"
+}
diff --git a/handsontable/src/plugins/emptyDataState/__tests__/plugins/dataProvider.spec.js b/handsontable/src/plugins/emptyDataState/__tests__/plugins/dataProvider.spec.js
index 7de904f46f..95fed1e987 100644
--- a/handsontable/src/plugins/emptyDataState/__tests__/plugins/dataProvider.spec.js
+++ b/handsontable/src/plugins/emptyDataState/__tests__/plugins/dataProvider.spec.js
@@ -333,4 +333,38 @@ describe('EmptyDataState with DataProvider plugin', () => {
.toBe('All rows hidden by filters');
expect(messageSpy).toHaveBeenCalledWith('filters');
});
+
+ it('should not scroll the page when fetchRows loads data for the first time', async() => {
+ // Push the grid below the browser viewport so scrollIntoView would actually scroll
+ const spacer = document.createElement('div');
+
+ spacer.style.height = '2000px';
+ document.body.insertBefore(spacer, spec().$container[0]);
+ window.scrollTo(0, 0);
+
+ let resolveFetch;
+ const fetchRows = () => new Promise((resolve) => {
+ resolveFetch = resolve;
+ });
+
+ handsontable({
+ data: [],
+ columns: [{ data: 'id' }, { data: 'name' }],
+ height: 300,
+ emptyDataState: true,
+ dataProvider: createDataProviderConfig({ fetchRows }),
+ });
+
+ await sleep(0);
+
+ const scrollBefore = window.scrollY;
+
+ resolveFetch({ rows: [{ id: 1, name: 'Alice' }], totalRows: 1 });
+
+ await sleep(50);
+
+ expect(window.scrollY).toBe(scrollBefore);
+
+ spacer.remove();
+ });
});
diff --git a/handsontable/src/plugins/emptyDataState/emptyDataState.js b/handsontable/src/plugins/emptyDataState/emptyDataState.js
index c2131b4fd8..627cbef894 100644
--- a/handsontable/src/plugins/emptyDataState/emptyDataState.js
+++ b/handsontable/src/plugins/emptyDataState/emptyDataState.js
@@ -575,7 +575,7 @@ export class EmptyDataState extends BasePlugin {
this.hot.view.render();
this.#selectionState = null;
} else {
- this.hot.selectCell(0, 0);
+ this.hot.selectCell(0, 0, undefined, undefined, false);
}
this.hot.runHooks('afterEmptyDataStateHide');