Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class DataController extends DataHelperMixin(modules.Controller) {

public dataSourceChanged!: Callback<[]>;

public rowIndicesCorrected!: Callback<[RowIndexCorrection]>;
public rowIndicesChanged!: Callback<[RowIndexCorrection]>;

protected _lastRenderingPageIndex?: number;

Expand Down Expand Up @@ -187,7 +187,7 @@ export class DataController extends DataHelperMixin(modules.Controller) {
}

protected callbackNames(): string[] {
return ['changed', 'loadingChanged', 'dataErrorOccurred', 'pageChanged', 'dataSourceChanged', 'pushed', 'rowIndicesCorrected'];
return ['changed', 'loadingChanged', 'dataErrorOccurred', 'pageChanged', 'dataSourceChanged', 'pushed', 'rowIndicesChanged'];
}

protected callbackFlags(name?: string): CallbackFlags | undefined {
Expand Down Expand Up @@ -1148,7 +1148,7 @@ export class DataController extends DataHelperMixin(modules.Controller) {
change.isLiveUpdate = true;
}

this.rowIndicesCorrected.fire(
this.rowIndicesChanged.fire(
(rowIndex: number): number => this.getRowIndexCorrection(rowIndex, oldItems, newIndexByKey),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import type { RowIndexCorrection } from '@ts/grids/grid_core/data_controller/typ
import type { EditingController } from '@ts/grids/grid_core/editing/m_editing';
import type { RowsView } from '@ts/grids/grid_core/views/m_rows_view';
import type { RowsViewScrollEvent } from '@ts/grids/grid_core/views/types';
import type { VirtualScrollingDataControllerExtension } from '@ts/grids/grid_core/virtual_scrolling/m_virtual_scrolling';
import { memoize } from '@ts/utils/memoize';

import {
Expand Down Expand Up @@ -128,7 +129,7 @@ export class KeyboardNavigationController extends KeyboardNavigationControllerCo

private _testInteractiveElement: any;

protected _dataController!: Controllers['data'];
protected _dataController!: DataController & Partial<VirtualScrollingDataControllerExtension>;

private _selectionController!: Controllers['selection'];

Expand Down Expand Up @@ -184,8 +185,8 @@ export class KeyboardNavigationController extends KeyboardNavigationControllerCo
this.initDocumentHandlers();

// init runs again on option changes, so drop the previous subscription first
this._dataController.rowIndicesCorrected.remove(this.handleRowIndicesCorrected);
this._dataController.rowIndicesCorrected.add(this.handleRowIndicesCorrected);
this._dataController.rowIndicesChanged.remove(this.rowIndicesChangedHandler);
this._dataController.rowIndicesChanged.add(this.rowIndicesChangedHandler);
}

public dispose(): void {
Expand All @@ -198,10 +199,10 @@ export class KeyboardNavigationController extends KeyboardNavigationControllerCo
);
clearTimeout(this._updateFocusTimeout);
accessibility.unsubscribeVisibilityChange();
this._dataController.rowIndicesCorrected.remove(this.handleRowIndicesCorrected);
this._dataController.rowIndicesChanged.remove(this.rowIndicesChangedHandler);
}

private readonly handleRowIndicesCorrected = (
private readonly rowIndicesChangedHandler = (
getRowIndexCorrection: RowIndexCorrection,
): void => {
const focusedCellPosition = this._focusedCellPosition;
Expand Down Expand Up @@ -2062,15 +2063,24 @@ export class KeyboardNavigationController extends KeyboardNavigationControllerCo
return this._isCellValid($cell);
}

private _isLastRow(rowIndex: number): boolean {
const dataController = this._dataController;
private getMaxRowIndex(): number {
const lastLoadedRowIndex = this._dataController.items().length - 1;
const virtualItemsCount = this._dataController.virtualItemsCount?.();

if (!virtualItemsCount) {
return lastLoadedRowIndex;
}

return lastLoadedRowIndex + this._dataController.getRowIndexOffset() + virtualItemsCount.end;
}

private _isLastRow(rowIndex: number): boolean {
if (this._isVirtualRowRender()) {
return rowIndex >= (dataController as any).getMaxRowIndex();
return rowIndex >= this.getMaxRowIndex();
}

const lastVisibleIndex = Math.max(
...dataController.items()
...this._dataController.items()
.map((item, index) => (item.visible !== false ? index : -1)),
);

Expand Down Expand Up @@ -3194,21 +3204,6 @@ const editing = (Base: ModuleType<EditingController>) => class EditingController
}
};

const data = (Base: ModuleType<DataController>) => class DataControllerKeyboardExtender extends Base {
private getMaxRowIndex() {
let result = this.items().length - 1;
// @ts-expect-error
const virtualItemsCount = this.virtualItemsCount();

if (virtualItemsCount) {
const rowIndexOffset = this.getRowIndexOffset();
result += rowIndexOffset + virtualItemsCount.end;
}

return result;
}
};

const adaptiveColumns = (Base: ModuleType<AdaptiveColumnsController>) => class AdaptiveColumnsKeyboardExtender extends Base {
protected _showHiddenCellsInView({ viewName, $cells, isCommandColumn }) {
super._showHiddenCellsInView.apply(this, arguments as any);
Expand Down Expand Up @@ -3259,7 +3254,6 @@ export const keyboardNavigationModule: import('../m_types').Module = {
},
controllers: {
editing,
data,
adaptiveColumns,
keyboardNavigation: keyboardNavigationScrollableA11yExtender,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Deferred, when } from '@js/core/utils/deferred';
import { isObject, isString } from '@js/core/utils/type';

import type { VirtualItemsCount } from './types';

const LEGACY_SCROLLING_MODE = 'scrolling.legacyMode';

const needTwoPagesLoading = (that) => that.option('scrolling.loadTwoPagesOnStart') || that._controller.isVirtual() || that._controller.getViewportItemIndex() > 0;
Expand Down Expand Up @@ -405,7 +407,7 @@ export class VirtualDataLoader {
return count;
}

private virtualItemsCount() {
public virtualItemsCount(): VirtualItemsCount {
let pageIndex = getBeginPageIndex(this);
if (pageIndex < 0) {
pageIndex = this._dataOptions.pageIndex();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** How many virtual (not loaded) items sit before and after the loaded window. */
export interface VirtualItemsCount {
begin: number;
end: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type { ErrorHandlingViewController } from '@ts/grids/grid_core/error_hand
import type { ModuleType } from '@ts/grids/grid_core/m_types';
import type { ResizingController } from '@ts/grids/grid_core/views/m_grid_view';
import type { RowsView } from '@ts/grids/grid_core/views/m_rows_view';
import type { VirtualItemsCount } from '@ts/grids/grid_core/virtual_data_loader/types';

import type { ChangedEvent } from '../data_source_adapter/types';
import gridCoreUtils from '../m_utils';
Expand Down Expand Up @@ -456,7 +457,16 @@ export const dataSourceAdapterExtender = (Base: ModuleType<DataSourceAdapter>) =
return proxyDataSourceAdapterMethod(this, 'loadIfNeed', [...arguments]);
}
};
export const data = (Base: ModuleType<DataController>) => class VirtualScrollingDataControllerExtender extends Base {

export interface VirtualScrollingDataControllerExtension {
virtualItemsCount: () => VirtualItemsCount | undefined;
}

export const virtualScrollingDataControllerExtender = (
Base: ModuleType<DataController>,
): ModuleType<
DataController & VirtualScrollingDataControllerExtension
> => class VirtualScrollingDataControllerExtender extends Base {
private _loadViewportParams: any;

private _allItems: any;
Expand Down Expand Up @@ -1278,16 +1288,14 @@ export const data = (Base: ModuleType<DataController>) => class VirtualScrolling
return viewportParams && viewportParams.skip + viewportParams.take;
}

private virtualItemsCount() {
public virtualItemsCount(): VirtualItemsCount | undefined {
const rowsScrollController = this._rowsScrollController;

if (rowsScrollController) {
// @ts-expect-error
return rowsScrollController.virtualItemsCount.apply(rowsScrollController, arguments);
return rowsScrollController.virtualItemsCount();
}

const dataSource = this._dataSource;
return dataSource?.virtualItemsCount.apply(dataSource, arguments);
return this._dataSource?.virtualItemsCount() as VirtualItemsCount | undefined;
}

public pageIndex(): number;
Expand Down Expand Up @@ -1960,7 +1968,7 @@ export const virtualScrollingModule = {
},
extenders: {
controllers: {
data,
data: virtualScrollingDataControllerExtender,
resizing,
},
views: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Deferred } from '@js/core/utils/deferred';
import { each } from '@js/core/utils/iterator';
import { isDefined } from '@js/core/utils/type';
import { getWindow } from '@js/core/utils/window';
import type { VirtualItemsCount } from '@ts/grids/grid_core/virtual_data_loader/types';

import gridCoreUtils from '../m_utils';
import { VirtualDataLoader } from '../virtual_data_loader/m_virtual_data_loader';
Expand Down Expand Up @@ -167,7 +168,7 @@ class VirtualScrollController {
return this._isVirtual;
}

private virtualItemsCount() {
public virtualItemsCount(): VirtualItemsCount | undefined {
if (isVirtualMode(this)) {
const dataOptions = this._dataOptions;
const totalItemsCount = dataOptions.totalItemsCount();
Expand All @@ -186,8 +187,7 @@ class VirtualScrollController {
};
}

// @ts-expect-error
return this._dataLoader.virtualItemsCount.apply(this._dataLoader, arguments);
return this._dataLoader.virtualItemsCount();
}

return undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import type { ModuleType } from '@ts/grids/grid_core/m_types';
import gridCoreUtils from '@ts/grids/grid_core/m_utils';
import type { RowsView } from '@ts/grids/grid_core/views/m_rows_view';
import {
data as virtualScrollingDataControllerExtender,
dataSourceAdapterExtender as virtualScrollingDataSourceAdapterExtender,
rowsView as virtualScrollingRowsViewExtender,
virtualScrollingDataControllerExtender,
virtualScrollingModule,
} from '@ts/grids/grid_core/virtual_scrolling/m_virtual_scrolling';

Expand Down
5 changes: 1 addition & 4 deletions packages/devextreme/testing/helpers/gridBaseMocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,8 @@ module.exports = function($, gridCore, columnResizingReordering, domUtils, commo
pageChanged: $.Callbacks(),
dataSourceChanged: $.Callbacks(),
pushed: $.Callbacks(),
rowIndicesCorrected: $.Callbacks(),
rowIndicesChanged: $.Callbacks(),
fireError: function() { },
getMaxRowIndex: function() {
this.items().length - 1;
},
loadViewport: commonUtils.noop,
updateViewport: commonUtils.noop,
getScrollingTimeout: function() {
Expand Down
Loading