Skip to content

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import type { DxElement } from '@js/core/element';
import type { dxElementWrapper } from '@js/core/renderer';
import type { Properties as PivotGridProperties } from '@js/ui/pivot_grid';
import type { ScrollOffset } from '@ts/core/utils/scroll';
import type { DefaultActionArgs } from '@ts/core/widget/component';
import type DOMComponent from '@ts/core/widget/dom_component';

import type { HeaderItemType, PivotGridColumnInfo } from '../data_controller/types';

export type AreaName = 'column' | 'row' | 'data' | 'fields';

export interface AreaItemCell extends PivotGridColumnInfo {
value?: unknown;
rowType?: HeaderItemType;
columnType?: HeaderItemType;
}

export type AreaItemOption<TName extends string> = TName extends keyof PivotGridProperties
? PivotGridProperties[TName]
: unknown;

export interface AreaItemComponent {
option: <TName extends string>(optionName: TName) => AreaItemOption<TName>;
$element: () => dxElementWrapper;
_createComponent: typeof DOMComponent.prototype._createComponent;
_dataController?: {
getColumnIndexOffset: () => number;
getRowIndexOffset: () => number;
};
_eventsStrategy: {
hasEvent: (eventName: string) => boolean;
};
_defaultActionArgs: () => DefaultActionArgs<unknown>;
_trigger: (eventName: string, eventArg: unknown) => void;
}

export interface AreaItemCellPosition {
cellIndex: number;
cellsCount: number;
rowIndex: number;
rowsCount: number;
rtlEnabled: boolean | undefined;
}

export interface AreaItemStyleOptions extends AreaItemCellPosition {
cellElement: undefined;
cell: AreaItemCell;
rowElement: undefined;
classArray: string[];
cssArray: string[];
}

export interface AreaItemCellContext extends AreaItemCellPosition {
encodeHtml: boolean | undefined;
isCellNavigationEnabled: boolean;
}

export interface AreaItemCellAriaIndexOptions {
areaName: AreaName;
rowIndex: number;
columnIndex: number;
columnIndexMap: Map<string, number> | null;
columnIndexOffset: number;
rowIndexOffset: number;
}

export interface AreaItemCellPreparedArgs {
area: AreaName;
rowIndex: number;
columnIndex: number;
cellElement: DxElement;
cell: AreaItemCell;
}

export interface AreaItemVirtualContentParams {
top?: number;
left?: number;
width: number;
height: number;
}

export interface AreaItemTableCss {
top?: number;
left?: number;
right?: number;
}

export interface AreaItemScrollEvent {
scrollOffset: ScrollOffset;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import {
} from '@jest/globals';
import $ from '@js/core/renderer';

import type { AreaItemCell, AreaItemComponent } from '../area_item/types';
import { FAKE_TABLE_CLASS } from '../keyboard_navigation/const';
import { DataArea } from './m_data_area';

const createComponent = (options: Record<string, unknown> = {}): unknown => ({
const createComponent = (options: Record<string, unknown> = {}): AreaItemComponent => ({
option: (optionName?: string): unknown => {
if (optionName === undefined) {
return {};
Expand All @@ -26,7 +27,7 @@ const createComponent = (options: Record<string, unknown> = {}): unknown => ({
},
_eventsStrategy: { hasEvent: () => false },
_defaultActionArgs: () => ({}),
});
}) as unknown as AreaItemComponent;

describe('DataArea', () => {
let container: HTMLElement = document.createElement('div');
Expand All @@ -36,7 +37,7 @@ describe('DataArea', () => {
[{ text: '3' }, { text: '4' }],
];

const renderDataArea = (data: unknown[]): DataArea => {
const renderDataArea = (data: AreaItemCell[][]): DataArea => {
const area = new DataArea(createComponent());

area.render($(container), data);
Expand Down Expand Up @@ -77,7 +78,7 @@ describe('DataArea', () => {
});

describe('setColumnsWidth', () => {
const getTableWidth = (): string => container.querySelector('table')!.style.width;
const getTableWidth = (): string | undefined => container.querySelector('table')?.style.width;

const getColumnWidths = (): string[] => Array
.from(container.querySelectorAll('col'))
Expand Down Expand Up @@ -145,16 +146,16 @@ describe('DataArea', () => {
return area;
};

const getFakeTable = (): HTMLElement => container.querySelector(`.${FAKE_TABLE_CLASS}`)!;
const getFakeTable = (): HTMLElement | null => container.querySelector(`.${FAKE_TABLE_CLASS}`);

it('should show the fake table at the position scrolled past the rendered table', () => {
const area = renderVirtualDataArea();

area.scrollTo({ left: POSITION_PAST_TABLE, top: POSITION_PAST_TABLE });

expect(getFakeTable().style.left).toBe(`${POSITION_PAST_TABLE}px`);
expect(getFakeTable().style.top).toBe(`${POSITION_PAST_TABLE}px`);
expect(getFakeTable().classList).not.toContain('dx-hidden');
expect(getFakeTable()?.style.left).toBe(`${POSITION_PAST_TABLE}px`);
expect(getFakeTable()?.style.top).toBe(`${POSITION_PAST_TABLE}px`);
expect(getFakeTable()?.classList).not.toContain('dx-hidden');
});

it('should hide the fake table when scrolled back to the rendered table', () => {
Expand All @@ -163,18 +164,18 @@ describe('DataArea', () => {
area.scrollTo({ left: POSITION_PAST_TABLE, top: POSITION_PAST_TABLE });
area.scrollTo({ left: TABLE_OFFSET, top: TABLE_OFFSET });

expect(getFakeTable().style.left).toBe(`${TABLE_OFFSET}px`);
expect(getFakeTable().style.top).toBe(`${TABLE_OFFSET}px`);
expect(getFakeTable().classList).toContain('dx-hidden');
expect(getFakeTable()?.style.left).toBe(`${TABLE_OFFSET}px`);
expect(getFakeTable()?.style.top).toBe(`${TABLE_OFFSET}px`);
expect(getFakeTable()?.classList).toContain('dx-hidden');
});

it('should offset the fake table from the right when rtlEnabled is true', () => {
const area = renderVirtualDataArea(true);

area.scrollTo({ left: POSITION_PAST_TABLE, top: TABLE_OFFSET });

expect(getFakeTable().style.right).toBe(`${POSITION_PAST_TABLE}px`);
expect(getFakeTable().classList).not.toContain('dx-hidden');
expect(getFakeTable()?.style.right).toBe(`${POSITION_PAST_TABLE}px`);
expect(getFakeTable()?.classList).not.toContain('dx-hidden');
});
});
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
/* eslint-disable class-methods-use-this */
import type { ScrollDirection } from '@js/common';
import type { dxElementWrapper } from '@js/core/renderer';
import $ from '@js/core/renderer';
import { setTabIndex } from '@js/ui/shared/accessibility';
import type { ScrollOffset } from '@ts/core/utils/scroll';
import supportUtils from '@ts/core/utils/support';

import { AreaItem } from '../area_item/m_area_item';
import type {
AreaItemCell,
AreaItemStyleOptions,
AreaItemVirtualContentParams,
AreaName,
} from '../area_item/types';
import { calculateScrollbarWidth } from '../widget_utils';

const PIVOTGRID_AREA_CLASS = 'dx-pivotgrid-area';
Expand All @@ -13,34 +21,39 @@ const PIVOTGRID_GRAND_TOTAL_CLASS = 'dx-grandtotal';
const PIVOTGRID_ROW_TOTAL_CLASS = 'dx-row-total';

class DataArea extends AreaItem {
_getAreaName() {
protected _getAreaName(): AreaName {
return 'data';
}

render(rootElement, data) {
public render(rootElement: dxElementWrapper, data: AreaItemCell[][]): void {
super.render(rootElement, data);

this._makeFirstCellFocusable();
}

_makeFirstCellFocusable() {
const firstCell = this.tableElement().get(0)?.querySelector('td');
protected _makeFirstCellFocusable(): void {
const firstCell = this.tableElement()?.get(0)?.querySelector('td');

if (firstCell) {
setTabIndex(this.component, $(firstCell));
}
}

_createGroupElement() {
protected _createGroupElement(): dxElementWrapper {
return $('<div>')
.addClass(PIVOTGRID_AREA_CLASS)
.addClass(PIVOTGRID_AREA_DATA_CLASS)
.css('borderTopWidth', 0);
}

_applyCustomStyles(options) {
const { cell } = options;
const { classArray } = options;
protected _applyCustomStyles(options: AreaItemStyleOptions): void {
const {
cell,
classArray,
cssArray,
rowIndex,
rowsCount,
} = options;

if (cell.rowType === 'T' || cell.columnType === 'T') {
classArray.push(PIVOTGRID_TOTAL_CLASS);
Expand All @@ -53,21 +66,21 @@ class DataArea extends AreaItem {
classArray.push(PIVOTGRID_ROW_TOTAL_CLASS);
}

if (options.rowIndex === options.rowsCount - 1) {
options.cssArray.push('border-bottom: 0px');
if (rowIndex === rowsCount - 1) {
cssArray.push('border-bottom: 0px');
}

super._applyCustomStyles(options);
}

_moveFakeTable(scrollPos) {
protected _moveFakeTable(scrollPos: ScrollOffset): void {
this._moveFakeTableHorizontally(scrollPos.left);
this._moveFakeTableTop(scrollPos.top);
super._moveFakeTable();
}

renderScrollable() {
this._groupElement.dxScrollable({
public renderScrollable(): void {
this.renderGroupScrollable({
useNative: this.getUseNativeValue(),
useSimulatedScrollbar: false,
rtlEnabled: this.component.option('rtlEnabled'),
Expand All @@ -77,26 +90,33 @@ class DataArea extends AreaItem {
});
}

getUseNativeValue() {
const { useNative } = this.component.option('scrolling');
public getUseNativeValue(): boolean {
const useNative = this.component.option('scrolling')?.useNative;

return useNative === 'auto'
? !!supportUtils.nativeScrolling
: !!useNative;
}

getScrollbarWidth() {
public getScrollbarWidth(): number {
return this.getUseNativeValue() ? calculateScrollbarWidth() : 0;
}

updateScrollableOptions({ direction, rtlEnabled }) {
public updateScrollableOptions({ direction, rtlEnabled }: {
direction: ScrollDirection;
rtlEnabled: boolean | undefined;
}): void {
const scrollable = this._getScrollable();

if (!scrollable) {
return;
}

scrollable.option('useNative', this.getUseNativeValue());
scrollable.option({ direction, rtlEnabled });
}

getScrollableDirection(horizontal, vertical) {
public getScrollableDirection(horizontal: boolean, vertical: boolean): ScrollDirection {
if (horizontal && !vertical) {
return 'horizontal';
} if (!horizontal && vertical) {
Expand All @@ -106,17 +126,17 @@ class DataArea extends AreaItem {
return 'both';
}

reset() {
public reset(): void {
super.reset();
if (this._virtualContent) {
this._virtualContent.parent().css('height', 'auto');
}
}

setVirtualContentParams(params) {
public setVirtualContentParams(params: AreaItemVirtualContentParams): void {
super.setVirtualContentParams(params);

this._virtualContent.parent().css('height', params.height);
this._virtualContent?.parent().css('height', params.height);

this._setTableCss({
top: params.top,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class DataProvider {
public getColumnsWidths(): number[] {
const colsArea = this._options.columnsArea;
const { rowsArea, columns } = this._options;
const useDefaultWidth = !hasWindow() || colsArea.option('scrolling.mode') === 'virtual' || colsArea.element().is(':hidden');
const useDefaultWidth = !hasWindow() || colsArea.option('scrolling.mode') === 'virtual' || colsArea.element()?.is(':hidden');
return useDefaultWidth
? columns.map(() => DEFAUL_COLUMN_WIDTH)
: rowsArea.getColumnsWidth().concat(colsArea.getColumnsWidth());
Expand Down
Loading
Loading