Skip to content

Commit 851f460

Browse files
DataGrid - Pager - Show correct pageIndex when virtualScrolling is enabled on pageSize change (DevExpress#33412)
Co-authored-by: anna.shakhova <anna.shakhova@devexpress.com>
1 parent ecfb0ec commit 851f460

5 files changed

Lines changed: 108 additions & 34 deletions

File tree

e2e/testcafe-devextreme/tests/dataGrid/common/pager.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,85 @@ test('Page index should not reset when scrolling while the grid is being refresh
238238
height: 440,
239239
}));
240240

241+
test('Pager info should show page 1 of 1 after changing pageSize to \'all\' with virtual scrolling (T1327238)', async (t) => {
242+
const dataGrid = new DataGrid('#container');
243+
const pager = dataGrid.getPager();
244+
245+
await t
246+
.expect(pager.getInfoText().textContent)
247+
.eql('Page 5 of 10 (100 items)');
248+
249+
await t
250+
.click(pager.getPageSize(1).element)
251+
.expect(pager.getInfoText().textContent)
252+
.eql('Page 1 of 1 (100 items)');
253+
}).before(async () => createWidget('dxDataGrid', {
254+
dataSource: [...new Array(100).keys()].map((i) => ({ id: i })),
255+
keyExpr: 'id',
256+
showBorders: true,
257+
scrolling: {
258+
mode: 'virtual',
259+
},
260+
paging: {
261+
pageSize: 10,
262+
pageIndex: 4,
263+
},
264+
pager: {
265+
visible: true,
266+
allowedPageSizes: [10, 'all'],
267+
showPageSizeSelector: true,
268+
showInfo: true,
269+
showNavigationButtons: true,
270+
},
271+
height: 400,
272+
}));
273+
274+
test('Pager info should show page 1 of 1 after changing pageSize to \'all\' and enabling virtual scrolling (T1327238)', async (t) => {
275+
const dataGrid = new DataGrid('#container');
276+
const pager = dataGrid.getPager();
277+
278+
await t
279+
.expect(pager.getInfoText().textContent)
280+
.eql('Page 5 of 10 (100 items)');
281+
282+
await t
283+
.click(pager.getPageSize(1).element)
284+
.expect(pager.getInfoText().textContent)
285+
.eql('Page 1 of 1 (100 items)');
286+
}).before(async () => createWidget('dxDataGrid', {
287+
dataSource: [...new Array(100).keys()].map((i) => ({ id: i })),
288+
keyExpr: 'id',
289+
showBorders: true,
290+
scrolling: {
291+
mode: 'standard',
292+
},
293+
paging: {
294+
pageSize: 10,
295+
pageIndex: 4,
296+
},
297+
pager: {
298+
visible: true,
299+
allowedPageSizes: [10, 'all'],
300+
showPageSizeSelector: true,
301+
showInfo: true,
302+
showNavigationButtons: true,
303+
},
304+
height: 400,
305+
onOptionChanged: (e) => {
306+
if (e.fullName === 'paging.pageSize') {
307+
const setVirtual = e.value === 0;
308+
const targetRenderingMode = setVirtual ? 'virtual' : 'standard';
309+
const currentRenderingMode = e.component.option('scrolling.mode');
310+
if (currentRenderingMode !== targetRenderingMode) {
311+
e.component.beginUpdate();
312+
e.component.option('scrolling.mode', targetRenderingMode);
313+
e.component.repaint();
314+
e.component.endUpdate();
315+
}
316+
}
317+
},
318+
}));
319+
241320
test('No error should occur if dataSource is not defined and pageIndex is promise chained (T1256070)', async (t) => {
242321
const dataGrid = new DataGrid('#container');
243322

packages/devextreme/js/__internal/grids/grid_core/data_controller/m_data_controller.ts

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ const changePaging = function (that, optionName, value) {
3636
if (value !== undefined) {
3737
const oldValue = that._getPagingOptionValue(optionName);
3838
if (oldValue !== value) {
39-
if (optionName === 'pageSize') {
39+
that._skipProcessingPagingChange = true;
40+
if (optionName === 'pageSize' && value === 0) {
4041
dataSource.pageIndex(0);
42+
that.option('paging.pageIndex', 0);
4143
}
4244
dataSource[optionName](value);
43-
44-
that._skipProcessingPagingChange = true;
4545
that.option(`paging.${optionName}`, value);
4646
that._skipProcessingPagingChange = false;
4747
const pageIndex = dataSource.pageIndex();
@@ -213,11 +213,7 @@ export class DataController extends DataHelperMixin(modules.Controller) {
213213

214214
this._isPaging = false;
215215
this._currentOperationTypes = null;
216-
this._dataChangedHandler = (e) => {
217-
this._currentOperationTypes = this._dataSource.operationTypes();
218-
this._handleDataChanged(e);
219-
this._currentOperationTypes = null;
220-
};
216+
this._dataChangedHandler = this._handleDataChanged.bind(this);
221217
this._columnsChangedHandler = this._handleColumnsChanged.bind(this);
222218
this._loadingChangedHandler = this._handleLoadingChanged.bind(this);
223219
this._loadErrorHandler = this._handleLoadError.bind(this);
@@ -588,6 +584,7 @@ export class DataController extends DataHelperMixin(modules.Controller) {
588584
errors.log('W1005', that.component.NAME);
589585
that._applyFilter();
590586
} else {
587+
this._currentOperationTypes = dataSource.operationTypes();
591588
that.updateItems(e, true);
592589
}
593590
}).fail(() => {
@@ -1170,6 +1167,8 @@ export class DataController extends DataHelperMixin(modules.Controller) {
11701167
const changeType = change.changeType || 'refresh';
11711168

11721169
change.changeType = changeType;
1170+
change.operationTypes ??= this._currentOperationTypes;
1171+
this._currentOperationTypes = null;
11731172

11741173
if (dataSource) {
11751174
const cachedProcessedItems = this._cachedProcessedItems;
@@ -1231,36 +1230,35 @@ export class DataController extends DataHelperMixin(modules.Controller) {
12311230
}
12321231
}
12331232

1234-
public updateItems(change?, isDataChanged?) {
1235-
change = change || {};
1236-
const that = this;
1237-
change.isFirstRender = !that.changed.fired();
1233+
public updateItems(change: any = {}, isDataChanged?: boolean) {
1234+
change.isFirstRender = !this.changed.fired();
12381235

1239-
if (that._repaintChangesOnly !== undefined) {
1240-
change.repaintChangesOnly = change.repaintChangesOnly ?? that._repaintChangesOnly;
1241-
change.needUpdateDimensions = change.needUpdateDimensions || that._needUpdateDimensions;
1236+
if (this._repaintChangesOnly !== undefined) {
1237+
change.repaintChangesOnly ??= this._repaintChangesOnly;
1238+
change.needUpdateDimensions = change.needUpdateDimensions || this._needUpdateDimensions;
12421239
} else if (change.changes) {
1243-
change.repaintChangesOnly = that.option('repaintChangesOnly');
1240+
change.repaintChangesOnly = this.option('repaintChangesOnly');
12441241
} else if (isDataChanged) {
1245-
const operationTypes = that.dataSource().operationTypes();
1242+
const operationTypes = this.dataSource().operationTypes();
12461243

1247-
change.repaintChangesOnly = operationTypes && !operationTypes.grouping && !operationTypes.filtering && that.option('repaintChangesOnly');
12481244
change.isDataChanged = true;
1245+
change.repaintChangesOnly = operationTypes && !operationTypes.grouping && !operationTypes.filtering && this.option('repaintChangesOnly');
1246+
12491247
if (operationTypes && (operationTypes.reload || operationTypes.paging || operationTypes.groupExpanding)) {
12501248
change.needUpdateDimensions = true;
12511249
}
12521250
}
12531251

1254-
if (that._updateLockCount && !change.cancel) {
1255-
that._changes.push(change);
1252+
if (this._updateLockCount && !change.cancel) {
1253+
this._changes.push(change);
12561254
return;
12571255
}
12581256

1259-
that._updateItemsCore(change);
1257+
this._updateItemsCore(change);
12601258

12611259
if (change.cancel) return;
12621260

1263-
that._fireChanged(change);
1261+
this._fireChanged(change);
12641262
}
12651263

12661264
public loadingOperationTypes() {
@@ -1273,10 +1271,6 @@ export class DataController extends DataHelperMixin(modules.Controller) {
12731271
* @extended: virtual_scrolling, focus
12741272
*/
12751273
protected _fireChanged(change) {
1276-
if (this._currentOperationTypes) {
1277-
change.operationTypes = this._currentOperationTypes;
1278-
this._currentOperationTypes = null;
1279-
}
12801274
deferRender(() => {
12811275
this.changed.fire(change);
12821276
});

packages/devextreme/js/__internal/grids/grid_core/virtual_scrolling/m_virtual_scrolling.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,18 +1004,19 @@ export const data = (Base: ModuleType<DataController>) => class VirtualScrolling
10041004
};
10051005
}
10061006

1007-
private _updateVisiblePageIndex(currentPageIndex?) {
1007+
private _updateVisiblePageIndex(value?: number): void {
10081008
if (!this._rowsScrollController) {
10091009
return;
10101010
}
1011-
if (isDefined(currentPageIndex)) {
1012-
this._silentOption(VISIBLE_PAGE_INDEX, currentPageIndex);
1011+
1012+
if (isDefined(value)) {
1013+
this._silentOption(VISIBLE_PAGE_INDEX, value);
10131014
this.pageChanged.fire();
10141015
return;
10151016
}
10161017

1017-
const viewPortItemIndex = this._rowsScrollController.getViewportItemIndex();
1018-
const newPageIndex = Math.floor(viewPortItemIndex / this.pageSize());
1018+
const viewportItemIndex = this._rowsScrollController.getViewportItemIndex();
1019+
const newPageIndex = Math.floor(viewportItemIndex / this.pageSize());
10191020

10201021
if (this.pageIndex() !== newPageIndex) {
10211022
this._silentOption(VISIBLE_PAGE_INDEX, newPageIndex);

packages/devextreme/testing/tests/DevExpress.ui.widgets.dataGrid/dataController.tests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3242,8 +3242,8 @@ QUnit.module('Paging', { beforeEach: setupPagingModule, afterEach: teardownPagin
32423242
// assert
32433243
assert.equal(this.dataController.items().length, 3);
32443244
assert.equal(this.dataController.pageCount(), 3);
3245-
assert.equal(this.dataController.pageIndex(), 0);
3246-
assert.deepEqual(this.dataController.items()[0].values, ['Alex', 215]);
3245+
assert.equal(this.dataController.pageIndex(), 1);
3246+
assert.deepEqual(this.dataController.items()[0].values, ['Dan3', 153]);
32473247

32483248
// T262949
32493249
assert.equal(countCallPageChanged, 1, 'count call pageChanged');

packages/devextreme/testing/tests/DevExpress.ui.widgets.dataGrid/keyboardNavigation.realControllers.tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ QUnit.module('Real DataController and ColumnsController', {
671671
this.cellValue(0, 2, '5');
672672
this.saveEditData();
673673
// assert
674-
assert.equal(focusedRowChangedFiresCount, 2, 'onFocusedRowChanged fires count');
674+
assert.equal(focusedRowChangedFiresCount, 1, 'onFocusedRowChanged fires count');
675675

676676
// act
677677
this.refresh();

0 commit comments

Comments
 (0)