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
5 changes: 3 additions & 2 deletions packages/devextreme/js/__internal/core/widget/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -611,9 +611,10 @@ export class Component<
}

option(): TProperties;
option<TPropertyName extends string>(
option<TPropertyName extends keyof TProperties & string>(
optionName: TPropertyName,
): TPropertyName extends keyof TProperties ? TProperties[TPropertyName] : unknown;
): TProperties[TPropertyName];
option(optionName: string): unknown;
option<TPropertyName extends string>(
optionName: TPropertyName,
optionValue: TPropertyName extends keyof TProperties ? TProperties[TPropertyName] : unknown,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ class PivotGridDataSource {
if (collectGroups || area === 'data') {
const areaFields: PivotGridField[] = [];

this._fields.forEach((field) => {
this.fields().forEach((field) => {
if (this.isAreaField(field, area)) {
areaFields.push(field);
}
Expand Down Expand Up @@ -1323,13 +1323,15 @@ class PivotGridDataSource {
public collapseAll(id: number | string): void {
let dataChanged = false;
const field = this.field(id) ?? {};
let areaOffsets = [this.getAreaFields(field.area).indexOf(field)];
const areaFields: PivotGridField[] = this.getAreaFields(field.area);
let areaOffsets = [areaFields.indexOf(field)];

field.expanded = false;
if (field.levels) {
areaOffsets = [];
field.levels.forEach((f) => {
areaOffsets.push(this.getAreaFields(field.area).indexOf(f));
const levelAreaFields: PivotGridField[] = this.getAreaFields(field.area);
areaOffsets.push(levelAreaFields.indexOf(f));
f.expanded = false;
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { Field } from '@js/ui/pivot_grid/data_source';
import type { DataKey } from '@ts/core/element_data';

export type FieldChooserField = Field & { index: number };
import type { PivotGridPreparedField } from '../types';

export const FIELD_DATA_KEY: DataKey<FieldChooserField> = 'field';
export const FIELD_DATA_KEY: DataKey<PivotGridPreparedField> = 'field';

export const ATTRIBUTES = {
treeViewItem: 'tree-view-item',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ import type {
OldSortableDraggingArgs,
OldSortableProperties,
} from '../sortable/types';
import type { PivotGridField } from '../types';
import type { FieldChooserField, SortOrderType } from './const';
import type { PivotGridField, PivotGridPreparedField } from '../types';
import type { SortOrderType } from './const';
import {
ATTRIBUTES, CLASSES, FIELD_DATA_KEY, FIELD_NAVIGATION_DELTAS,
} from './const';
Expand Down Expand Up @@ -80,7 +80,9 @@ class HeaderFilterView extends HeaderFilterViewBase {
// @ts-expect-error the sorting and column state mixins are typed for grid views
const mixinWidget: typeof Widget = sortingMixin(columnStateMixin(Widget));

export class FieldChooserBase extends mixinWidget<FieldChooserBaseProperties> {
export class FieldChooserBase<
TProperties extends FieldChooserBaseProperties = FieldChooserBaseProperties,
> extends mixinWidget<TProperties> {
protected declare _applyColumnState: (
options: ColumnStateOptions,
) => dxElementWrapper | undefined;
Expand All @@ -101,7 +103,7 @@ export class FieldChooserBase extends mixinWidget<FieldChooserBaseProperties> {
// built on the legacy DevExtreme class system in the systemjs build.
private _fieldNavigationMap: Record<string, RovingTabIndex> | undefined;

public _getDefaultOptions(): FieldChooserBaseProperties {
public _getDefaultOptions(): TProperties {
return {
...super._getDefaultOptions(),
...{
Expand Down Expand Up @@ -166,27 +168,31 @@ export class FieldChooserBase extends mixinWidget<FieldChooserBaseProperties> {
});
}

public _optionChanged(args: OptionChanged<FieldChooserBaseProperties>): void {
public _optionChanged(args: OptionChanged<TProperties>): void {
switch (args.name) {
case 'dataSource':
this._refreshDataSource();
break;
case 'applyChangesMode':
case 'remoteSort':
break;
case 'state':
case 'state': {
if (this._skipStateChange || !this._dataSource) {
break;
}

// The name check can't narrow args on the generic TProperties.
const state = args.value as FieldChooserBaseProperties['state'];

if (this.option('applyChangesMode') === 'instantly'
&& getStringState(this._dataSource.state()) !== getStringState(args.value)) {
this._dataSource.state(args.value);
&& getStringState(this._dataSource.state()) !== getStringState(state)) {
this._dataSource.state(state);
} else {
this._clean(true);
this._renderComponent();
}
break;
}
case 'headerFilter':
case 'allowFieldDragging':
this._invalidate();
Expand All @@ -196,7 +202,7 @@ export class FieldChooserBase extends mixinWidget<FieldChooserBaseProperties> {
}
}

public renderField(field: FieldChooserField, showColumnLines: boolean): dxElementWrapper {
public renderField(field: PivotGridPreparedField, showColumnLines: boolean): dxElementWrapper {
const caption = field.caption ?? field.dataField ?? '';
const $fieldContent = $(DIV).addClass(CLASSES.area.fieldContent)
.text(caption);
Expand Down Expand Up @@ -342,7 +348,7 @@ export class FieldChooserBase extends mixinWidget<FieldChooserBaseProperties> {
return result;
}

protected _applyChanges(fields: FieldChooserField[], props: Partial<PivotGridField>): void {
protected _applyChanges(fields: PivotGridPreparedField[], props: Partial<PivotGridField>): void {
this._processDemandState((dataSource, isInstantlyMode) => {
fields.forEach(({ index }) => {
dataSource.field(index, props);
Expand Down Expand Up @@ -541,7 +547,7 @@ export class FieldChooserBase extends mixinWidget<FieldChooserBaseProperties> {

private _handleFieldNavigation(
e: FieldChooserFieldEvent<KeyboardEvent>,
field: FieldChooserField,
field: PivotGridPreparedField,
): void {
if (!field.area) {
return;
Expand All @@ -568,7 +574,7 @@ export class FieldChooserBase extends mixinWidget<FieldChooserBaseProperties> {

private _renderHeaderFilterIcon(
$fieldElement: dxElementWrapper,
field: FieldChooserField,
field: PivotGridPreparedField,
showColumnLines: boolean,
): void {
if (!this._dataSource || !fieldHasHeaderFilter(this._dataSource, field)) {
Expand Down Expand Up @@ -598,7 +604,10 @@ export class FieldChooserBase extends mixinWidget<FieldChooserBaseProperties> {
$container.append($icon);
}

private handleHeaderFilterIconClick(e: FieldChooserFieldEvent, field: FieldChooserField): void {
private handleHeaderFilterIconClick(
e: FieldChooserFieldEvent,
field: PivotGridPreparedField,
): void {
// eslint-disable-next-line @typescript-eslint/no-this-alias -- the methods use their own this
const that = this;
const dataSource = this._dataSource;
Expand Down Expand Up @@ -673,7 +682,7 @@ export class FieldChooserBase extends mixinWidget<FieldChooserBaseProperties> {
}));
}

private handleFieldClick(field: FieldChooserField): void {
private handleFieldClick(field: PivotGridPreparedField): void {
const isRemoteSort = this.option('remoteSort');
const sortOrder = reverseSortOrder(field.sortOrder);

Expand Down
Loading