Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions e2e/testcafe-devextreme/tests/dataGrid/common/pager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,85 @@ test('Page index should not reset when scrolling while the grid is being refresh
height: 440,
}));

test('Pager info should show page 1 of 1 after changing pageSize to \'all\' with virtual scrolling (T1327238)', async (t) => {
const dataGrid = new DataGrid('#container');
const pager = dataGrid.getPager();

await t
.expect(pager.getInfoText().textContent)
.eql('Page 5 of 10 (100 items)');

await t
.click(pager.getPageSize(1).element)
.expect(pager.getInfoText().textContent)
.eql('Page 1 of 1 (100 items)');
}).before(async () => createWidget('dxDataGrid', {
dataSource: [...new Array(100).keys()].map((i) => ({ id: i })),
keyExpr: 'id',
showBorders: true,
scrolling: {
mode: 'virtual',
},
paging: {
pageSize: 10,
pageIndex: 4,
},
pager: {
visible: true,
allowedPageSizes: [10, 'all'],
showPageSizeSelector: true,
showInfo: true,
showNavigationButtons: true,
},
height: 400,
}));

test('Pager info should show page 1 of 1 after changing pageSize to \'all\' and enabling virtual scrolling (T1327238)', async (t) => {
const dataGrid = new DataGrid('#container');
const pager = dataGrid.getPager();

await t
.expect(pager.getInfoText().textContent)
.eql('Page 5 of 10 (100 items)');

await t
.click(pager.getPageSize(1).element)
.expect(pager.getInfoText().textContent)
.eql('Page 1 of 1 (100 items)');
}).before(async () => createWidget('dxDataGrid', {
dataSource: [...new Array(100).keys()].map((i) => ({ id: i })),
keyExpr: 'id',
showBorders: true,
scrolling: {
mode: 'standard',
},
paging: {
pageSize: 10,
pageIndex: 4,
},
pager: {
visible: true,
allowedPageSizes: [10, 'all'],
showPageSizeSelector: true,
showInfo: true,
showNavigationButtons: true,
},
height: 400,
onOptionChanged(e){
if (e.fullName === "paging.pageSize") {
const setVirtual = e.value === 0;
const targetRenderingMode = setVirtual ? "virtual" : "standard";
const currentRenderingMode = e.component.option("scrolling.mode");
if (currentRenderingMode !== targetRenderingMode) {
e.component.beginUpdate();
e.component.option("scrolling.mode", targetRenderingMode);
e.component.repaint();
e.component.endUpdate();
}
Comment on lines +305 to +315
}
},
}));

test('No error should occur if dataSource is not defined and pageIndex is promise chained (T1256070)', async (t) => {
const dataGrid = new DataGrid('#container');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ const changePaging = function (that, optionName, value) {

that._skipProcessingPagingChange = true;
that.option(`paging.${optionName}`, value);
if (optionName === 'pageSize') {
that.option('paging.pageIndex', 0);
}
that._skipProcessingPagingChange = false;
const pageIndex = dataSource.pageIndex();
that._isPaging = optionName === 'pageIndex';
Expand Down Expand Up @@ -213,11 +216,7 @@ export class DataController extends DataHelperMixin(modules.Controller) {

this._isPaging = false;
this._currentOperationTypes = null;
this._dataChangedHandler = (e) => {
this._currentOperationTypes = this._dataSource.operationTypes();
this._handleDataChanged(e);
this._currentOperationTypes = null;
};
this._dataChangedHandler = this._handleDataChanged.bind(this);
this._columnsChangedHandler = this._handleColumnsChanged.bind(this);
this._loadingChangedHandler = this._handleLoadingChanged.bind(this);
this._loadErrorHandler = this._handleLoadError.bind(this);
Expand Down Expand Up @@ -588,6 +587,7 @@ export class DataController extends DataHelperMixin(modules.Controller) {
errors.log('W1005', that.component.NAME);
that._applyFilter();
} else {
this._currentOperationTypes = dataSource.operationTypes();
that.updateItems(e, true);
}
}).fail(() => {
Expand Down Expand Up @@ -1170,6 +1170,8 @@ export class DataController extends DataHelperMixin(modules.Controller) {
const changeType = change.changeType || 'refresh';

change.changeType = changeType;
change.operationTypes = this._currentOperationTypes;
this._currentOperationTypes = null;

if (dataSource) {
const cachedProcessedItems = this._cachedProcessedItems;
Expand Down Expand Up @@ -1231,36 +1233,32 @@ export class DataController extends DataHelperMixin(modules.Controller) {
}
}

public updateItems(change?, isDataChanged?) {
change = change || {};
const that = this;
change.isFirstRender = !that.changed.fired();
public updateItems(change: any = {}, isDataChanged?: boolean) {
change.isFirstRender = !this.changed.fired();

if (that._repaintChangesOnly !== undefined) {
change.repaintChangesOnly = change.repaintChangesOnly ?? that._repaintChangesOnly;
change.needUpdateDimensions = change.needUpdateDimensions || that._needUpdateDimensions;
if (this._repaintChangesOnly !== undefined) {
change.repaintChangesOnly ??= this._repaintChangesOnly;
change.needUpdateDimensions ??= this._needUpdateDimensions;
} else if (change.changes) {
change.repaintChangesOnly = that.option('repaintChangesOnly');
change.repaintChangesOnly = this.option('repaintChangesOnly');
} else if (isDataChanged) {
const operationTypes = that.dataSource().operationTypes();
const operationTypes = this.dataSource().operationTypes();

change.repaintChangesOnly = operationTypes && !operationTypes.grouping && !operationTypes.filtering && that.option('repaintChangesOnly');
change.isDataChanged = true;
if (operationTypes && (operationTypes.reload || operationTypes.paging || operationTypes.groupExpanding)) {
change.needUpdateDimensions = true;
}
change.repaintChangesOnly = operationTypes && !operationTypes.grouping && !operationTypes.filtering && this.option('repaintChangesOnly');
change.needUpdateDimensions = operationTypes && (operationTypes.reload || operationTypes.paging || operationTypes.groupExpanding);
}

if (that._updateLockCount && !change.cancel) {
that._changes.push(change);
if (this._updateLockCount && !change.cancel) {
this._changes.push(change);
return;
}

that._updateItemsCore(change);
this._updateItemsCore(change);

if (change.cancel) return;

that._fireChanged(change);
this._fireChanged(change);
}

public loadingOperationTypes() {
Expand All @@ -1273,10 +1271,6 @@ export class DataController extends DataHelperMixin(modules.Controller) {
* @extended: virtual_scrolling, focus
*/
protected _fireChanged(change) {
if (this._currentOperationTypes) {
change.operationTypes = this._currentOperationTypes;
this._currentOperationTypes = null;
}
deferRender(() => {
this.changed.fire(change);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1004,18 +1004,19 @@ export const data = (Base: ModuleType<DataController>) => class VirtualScrolling
};
}

private _updateVisiblePageIndex(currentPageIndex?) {
private _updateVisiblePageIndex(value?: number): void {
if (!this._rowsScrollController) {
return;
}
if (isDefined(currentPageIndex)) {
this._silentOption(VISIBLE_PAGE_INDEX, currentPageIndex);

if (isDefined(value)) {
this._silentOption(VISIBLE_PAGE_INDEX, value);
this.pageChanged.fire();
return;
}

const viewPortItemIndex = this._rowsScrollController.getViewportItemIndex();
const newPageIndex = Math.floor(viewPortItemIndex / this.pageSize());
const viewportItemIndex = this._rowsScrollController.getViewportItemIndex();
const newPageIndex = Math.floor(viewportItemIndex / this.pageSize());

if (this.pageIndex() !== newPageIndex) {
this._silentOption(VISIBLE_PAGE_INDEX, newPageIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ QUnit.module('Real DataController and ColumnsController', {
this.cellValue(0, 2, '5');
this.saveEditData();
// assert
assert.equal(focusedRowChangedFiresCount, 2, 'onFocusedRowChanged fires count');
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name of the test suggest that focusedRowChangedFiresCount should increase after refresh, but current test doesn't check it.

Initial test did it, though: link

assert.equal(focusedRowChangedFiresCount, 1, 'onFocusedRowChanged fires count');

// act
this.refresh();
Expand Down
Loading