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
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { equalByValue } from '@js/core/utils/common';
import { compileGetter } from '@js/core/utils/data';
import { Deferred } from '@js/core/utils/deferred';
import { isDefined } from '@js/core/utils/type';
import type { DataController } from '@ts/grids/grid_core/data_controller/data_controller';
import { focusModule } from '@ts/grids/grid_core/focus/m_focus';
import type { ModuleType } from '@ts/grids/grid_core/m_types';

import type { GroupingDataControllerExtension } from '../grouping/m_grouping';
import type { GroupingDataControllerExtension, GroupingDataSourceAdapter } from '../grouping/m_grouping';
import gridCore from '../m_core';
import { createGroupFilter } from '../m_utils';

Expand All @@ -25,6 +24,8 @@ DataController
& GroupingDataControllerExtension>;

const data = (Base: DataControllerBase) => class FocusDataControllerExtender extends focusModule.extenders.controllers.data(Base) {
public declare _dataSource?: GroupingDataSourceAdapter | null;

private changeRowExpand(path, isRowClick) {
// @ts-expect-error
if (this.option('focusedRowEnabled') && Array.isArray(path) && this.isRowExpanded(path)) {
Expand Down Expand Up @@ -100,7 +101,6 @@ const data = (Base: DataControllerBase) => class FocusDataControllerExtender ext

const group = dataSource.group();

// @ts-expect-error badly typed DataSourceAdapter
if (!dataSource._grouping._updatePagingOptions) {
this._calculateGlobalRowIndexByFlatData(key, null, true)
.done(deferred.resolve)
Expand All @@ -112,15 +112,13 @@ const data = (Base: DataControllerBase) => class FocusDataControllerExtender ext
filter: this._concatWithCombinedFilter(filter),
group,
}).done((data) => {
// @ts-expect-error badly typed DataSourceAdapter
const hasData = isDefined(data) && data.length > 0;
const hasData = Array.isArray(data) && data.length > 0;

if (this._dataSource !== dataSource || !hasData) {
return deferred.resolve(-1).promise();
}

// @ts-expect-error badly typed DataSourceAdapter
const groupPath = this._getGroupPath(data, group.length);
const groupPath = this._getGroupPath(data, gridCore.normalizeSortingInfo(group).length);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

was adding normalizeSortingInfo intentional? Why is it needed?

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.

yes - with the @ts-expect-error gone, group() is typed GroupDescriptor | GroupDescriptor[] | undefined, which has no .length. normalizeSortingInfo(group) gives an array to count from, same as in m_grouping.ts


this._expandGroupByPath(this, groupPath, 0).done(() => {
this._calculateExpandedRowGlobalIndex(deferred, key, groupPath, group, dataSource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
RowKey,
} from '@ts/grids/grid_core/m_types';

import type { GroupingDataSourceAdapter } from '../m_grouping';
import type {
ChangeRowExpandArgs, GroupItem, ProcessGroupItemsOptions,
} from '../types';
Expand All @@ -21,6 +22,8 @@ import {
export const groupingDataControllerExtender = (
Base: ModuleType<DataController>,
): ModuleType<DataController> => class GroupingDataControllerExtender extends Base {
public declare _dataSource?: GroupingDataSourceAdapter | null;

public init(): void {
super.init();

Expand Down Expand Up @@ -148,7 +151,6 @@ export const groupingDataControllerExtender = (

private collapseAll(groupIndex: number): void {
const dataSource = this._dataSource;
// @ts-expect-error badly typed DataSourceAdapter
if (dataSource?.collapseAll(groupIndex)) {
dataSource?.pageIndex(0);
dataSource?.reload();
Expand All @@ -157,7 +159,6 @@ export const groupingDataControllerExtender = (

private expandAll(groupIndex: number): void {
const dataSource = this._dataSource;
// @ts-expect-error badly typed DataSourceAdapter
if (dataSource?.expandAll(groupIndex)) {
dataSource?.pageIndex(0);
dataSource?.reload();
Expand Down Expand Up @@ -201,7 +202,6 @@ export const groupingDataControllerExtender = (
}

private isRowExpanded(key: RowKey): boolean {
// @ts-expect-error badly typed DataSourceAdapter
return !!this._dataSource?.isRowExpanded(key);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ export interface GroupingDataControllerExtension {
changeRowExpand(key, isRowClick?): any;
}

export type GroupingDataSourceAdapter = InstanceType<ReturnType<typeof dataSourceAdapterExtender>>;

const dataSourceAdapterExtender = (Base: ModuleType<DataSourceAdapter>) => class GroupingDataSourceAdapterExtender extends Base {
private _grouping: any;
public _grouping: any;

public init() {
super.init.apply(this, arguments as any);
Expand Down Expand Up @@ -76,16 +78,16 @@ const dataSourceAdapterExtender = (Base: ModuleType<DataSourceAdapter>) => class
return this._grouping.isGroupItemCountable(item);
}

private isRowExpanded(key) {
public isRowExpanded(key) {
const groupInfo = this._grouping.findGroupInfo(key);
return groupInfo ? groupInfo.isExpanded : !this._grouping.allowCollapseAll();
}

private collapseAll(groupIndex) {
public collapseAll(groupIndex) {
return this._collapseExpandAll(groupIndex, false);
}

private expandAll(groupIndex) {
public expandAll(groupIndex) {
return this._collapseExpandAll(groupIndex, true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { isSameContinuationState } from '../../grouping/utils';
import gridCore from '../../m_core';
import { isDataColumn } from '../../m_utils';
import { DATAGRID_GROUP_FOOTER_ROW_TYPE, DATAGRID_TOTAL_FOOTER_ROW_TYPE } from '../const';
import type { SummaryDataSourceAdapter } from '../m_summary';
import type {
CalculateSummaryCellsArgs, ColumnMap, FooterItem, SummaryCellItem,
SummaryGroupItem,
Expand All @@ -26,6 +27,8 @@ import { getSummaryItemIndex } from '../utils/get_summary_item_index';
export const summaryDataControllerExtender = (
Base: ModuleType<DataController>,
): ModuleType<DataController> => class SummaryDataControllerExtender extends Base {
public declare _dataSource?: SummaryDataSourceAdapter | null;

private _footerItems!: FooterItem[];

public init(): void {
Expand All @@ -43,8 +46,7 @@ export const summaryDataControllerExtender = (

public getTotalSummaryValue(summaryItemName?: string | number | null): unknown {
const summaryItemIndex = getSummaryItemIndex(this.option('summary.totalItems'), summaryItemName);
// @ts-expect-error badly typed DataSourceAdapter
const aggregates = this._dataSource.totalAggregates();
const aggregates = this._dataSource?.totalAggregates() ?? [];

if (aggregates.length && summaryItemIndex > -1) {
return aggregates[summaryItemIndex];
Expand Down Expand Up @@ -294,7 +296,6 @@ export const summaryDataControllerExtender = (
this._footerItems = [];

if (dataSource && summaryTotalItems?.length) {
// @ts-expect-error badly typed DataSourceAdapter
const totalAggregates = dataSource.totalAggregates();
const summaryCells = this._getSummaryCells(summaryTotalItems, totalAggregates);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import {
import type { Aggregate, SummaryOptions } from './types';
import { getSummaryOptions } from './utils/get_summary_options';

export type SummaryDataSourceAdapter = InstanceType<ReturnType<typeof summaryDataSourceAdapterExtender>>;

export const renderSummaryCell = function (cell, options, setAria) {
const $cell = $(cell);
const { column } = options;
Expand Down Expand Up @@ -256,7 +258,7 @@ export class FooterView extends ColumnsView {

export const summaryDataSourceAdapterExtender = (
Base: ModuleType<DataSourceAdapter>,
): ModuleType<DataSourceAdapter> => class SummaryDataSourceAdapterExtender
) => class SummaryDataSourceAdapterExtender
extends Base
implements EditingControllerRequired {
private _totalAggregates!: unknown[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export class DataController extends modules.Controller {
*/
protected _getPagingOptionValue(optionName: PagingOptionName): number {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return this._dataSource![optionName]() as number;
return this._dataSource![optionName]();
}

protected callbackNames(): string[] {
Expand Down Expand Up @@ -1179,7 +1179,8 @@ export class DataController extends modules.Controller {
// change.items at this stage is defined only if virtualScrolling
// + legacyScrollingMode enabled
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const dataItems = this._beforeProcessItems(change.items ?? this._dataSource!.items());
const items = (change.items ?? this._dataSource!.items()) as RawItemData[];
const dataItems = this._beforeProcessItems(items);
const processedItems = this._processItems(dataItems, change);

this._cachedProcessedItems = processedItems;
Expand Down Expand Up @@ -1240,7 +1241,7 @@ export class DataController extends modules.Controller {
return;
}

const operationTypes: OperationTypes | undefined = this.dataSource().operationTypes();
const operationTypes = this.dataSource()?.operationTypes() ?? undefined;

change.isDataChanged = true;
change.repaintChangesOnly = resolveRepaintChangesOnly(
Expand Down Expand Up @@ -1471,13 +1472,12 @@ export class DataController extends modules.Controller {
return this._dataSource ? this._dataSource.pageCount() : 1;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
public dataSource(): any {
return this._dataSource;
public dataSource(): DataSourceAdapter | undefined {
return this._dataSource ?? undefined;
}

public store(): Store | undefined {
return this._dataSource?.store() as Store | undefined;
return this._dataSource?.store();
}

public loadAll(data?: RawItemData[], skipFilter = false): DeferredObj<ProcessedItem[]> {
Expand Down Expand Up @@ -1586,7 +1586,7 @@ export class DataController extends modules.Controller {
}

if (value === undefined) {
return dataSource[optionName]() as number;

@Tucchhaa Tucchhaa Sep 2, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's add return type to DataController.dataSource() :

return dataSource[optionName]();
}

const oldValue = this._getPagingOptionValue(optionName);
Expand All @@ -1606,8 +1606,7 @@ export class DataController extends modules.Controller {
this._skipProcessingPagingChange = false;
}

// @ts-expect-error badly typed DataSourceAdapter
const pageIndex: number = dataSource.pageIndex();
const pageIndex = dataSource.pageIndex();
this._isPaging = optionName === 'pageIndex';

const loadResult: DeferredObj<unknown> = dataSource[optionName === 'pageIndex' ? 'load' : 'reload']();
Expand Down Expand Up @@ -1733,7 +1732,7 @@ export class DataController extends modules.Controller {
}

public getCachedStoreData(): RawItemData[] | undefined {
return this._dataSource?.getCachedStoreData() as RawItemData[] | undefined;
return this._dataSource?.getCachedStoreData();
}

/**
Expand All @@ -1757,9 +1756,8 @@ export class DataController extends modules.Controller {
return this._dataSource?.reload(reload, changesOnly) as DeferredObj<unknown>;
}

public push(...args: unknown[]): unknown {
// @ts-expect-error badly typed DataSourceAdapter
return this._dataSource?.push(...args);
public push(changes: StoreChange[], fromStore = false): void {
this._dataSource?.push(changes, fromStore);
}

private itemsCount(): number {
Expand All @@ -1778,7 +1776,7 @@ export class DataController extends modules.Controller {
* @extended: state_storing
*/
public isLoaded(): boolean {
return (this._dataSource ? this._dataSource.isLoaded() : true) as boolean;
return (this._dataSource ? this._dataSource.isLoaded() : true);
}

public totalCount(): number {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { SearchOperation } from '@js/common/data.types';
import type { ScalarFilterValue } from '@js/common/grids';
import type { DeferredObj } from '@js/core/utils/deferred';
import type { DataSource } from '@ts/data/data_source/types';

import type { Column } from '../columns_controller/types';
import type { ChangedEvent, OperationTypes, RawItemData } from '../data_source_adapter/types';
Expand Down Expand Up @@ -142,12 +141,6 @@ export type ItemChange = | { type: 'insert'; index: number; data: ProcessedItem
| { type: 'update'; index: number; data: ProcessedItem; oldItem: ProcessedItem }
| { type: 'remove'; index: number; oldItem: ProcessedItem };

/** data source */

export interface DataSourceAdapterLike {
_dataSource: DataSource;
}

/** callbacks */

export interface CallbackFlags {
Expand Down
Loading
Loading