From 943c7ee54ca05b57f0e648d35ee4f92f4e3f7668 Mon Sep 17 00:00:00 2001 From: Konstantin Volnyagin Date: Wed, 5 Feb 2020 16:21:50 +0300 Subject: [PATCH] TreeList: Fix navigateTo to the same page with row expanding after #11724 (#11895) --- js/ui/grid_core/ui.grid_core.focus.js | 16 +++++++++++--- .../treeList.tests.js | 21 +++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/js/ui/grid_core/ui.grid_core.focus.js b/js/ui/grid_core/ui.grid_core.focus.js index 3d444f78998c..77c9a9594c8c 100644 --- a/js/ui/grid_core/ui.grid_core.focus.js +++ b/js/ui/grid_core/ui.grid_core.focus.js @@ -186,9 +186,19 @@ exports.FocusController = core.ViewController.inherit((function() { d.resolve(-1); return; } - dataController.pageIndex(pageIndex).done(function() { - that._navigateTo(key, d, needFocusRow); - }).fail(d.reject); + if(pageIndex === dataController.pageIndex()) { + dataController.reload().done(function() { + if(that.isRowFocused(key)) { + d.resolve(that.getFocusedRowIndexByKey(key)); + } else { + that._navigateTo(key, d, needFocusRow); + } + }).fail(d.reject); + } else { + dataController.pageIndex(pageIndex).done(function() { + that._navigateTo(key, d, needFocusRow); + }).fail(d.reject); + } }).fail(d.reject); } diff --git a/testing/tests/DevExpress.ui.widgets.treeList/treeList.tests.js b/testing/tests/DevExpress.ui.widgets.treeList/treeList.tests.js index 0038068f3aa6..faf1ac547d0f 100644 --- a/testing/tests/DevExpress.ui.widgets.treeList/treeList.tests.js +++ b/testing/tests/DevExpress.ui.widgets.treeList/treeList.tests.js @@ -1403,10 +1403,31 @@ QUnit.test('TreeList navigateTo', function(assert) { this.clock.tick(); // assert + assert.deepEqual(treeList.option('expandedRowKeys'), [11], 'parent node is expanded'); assert.equal(treeList.pageIndex(), 1, 'page is changed'); assert.ok(treeList.getRowIndexByKey(12) >= 0, 'key is visible'); }); +QUnit.test('TreeList navigateTo to the same page with expand', function(assert) { + // arrange, act + const treeList = createTreeList({ + dataSource: generateData(10), + paging: { + pageSize: 4 + } + }); + + this.clock.tick(); + + treeList.navigateToRow(2); + this.clock.tick(); + + // assert + assert.deepEqual(treeList.option('expandedRowKeys'), [1], 'parent node is expanded'); + assert.equal(treeList.pageIndex(), 0, 'page is not changed'); + assert.ok(treeList.getRowIndexByKey(2) >= 0, 'key is visible'); +}); + // T697860 QUnit.test('dataSource change with columns should force one loading only', function(assert) { const loadingSpy = sinon.spy();