Skip to content

Commit 2ea1f17

Browse files
author
Alyar
committed
update first-cell classes on adaptive changes
1 parent 3270dcb commit 2ea1f17

4 files changed

Lines changed: 48 additions & 49 deletions

File tree

packages/devextreme/js/__internal/grids/grid_core/adaptivity/m_adaptivity.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ import gridCoreUtils from '../m_utils';
3535
import type { RowsView } from '../views/m_rows_view';
3636
import { getHideableColumns } from './utils';
3737

38-
const COLUMN_HEADERS_VIEW = 'columnHeadersView';
39-
const ROWS_VIEW = 'rowsView';
40-
const FOOTER_VIEW = 'footerView';
41-
const COLUMN_VIEWS = [COLUMN_HEADERS_VIEW, ROWS_VIEW, FOOTER_VIEW];
38+
const COLUMN_HEADERS_VIEW = 'columnHeadersView' as const;
39+
const ROWS_VIEW = 'rowsView' as const;
40+
const FOOTER_VIEW = 'footerView' as const;
41+
const COLUMN_VIEWS = [COLUMN_HEADERS_VIEW, ROWS_VIEW, FOOTER_VIEW] as const;
4242

4343
const ADAPTIVE_NAMESPACE = 'dxDataGridAdaptivity';
4444
const HIDDEN_COLUMNS_WIDTH = 'adaptiveHidden';
@@ -497,8 +497,6 @@ export class AdaptiveColumnsController extends modules.ViewController {
497497

498498
public _showHiddenColumns() {
499499
for (let i = 0; i < COLUMN_VIEWS.length; i++) {
500-
// TODO getView
501-
// @ts-expect-error
502500
const view = this.getView(COLUMN_VIEWS[i]);
503501
if (view && view.isVisible() && view.element()) {
504502
const viewName = view.name;
@@ -546,8 +544,6 @@ export class AdaptiveColumnsController extends modules.ViewController {
546544
private _hideVisibleColumn({ isCommandColumn, visibleIndex }: any) {
547545
const that = this;
548546
COLUMN_VIEWS.forEach((viewName) => {
549-
// TODO: getView
550-
// @ts-expect-error
551547
const view = that.getView(viewName);
552548
view && that._hideVisibleColumnInView({ view, isCommandColumn, visibleIndex });
553549
});
@@ -1322,7 +1318,22 @@ const resizing = (Base: ModuleType<ResizingController>) => class AdaptivityResiz
13221318
return super._needBestFit() || !!this._adaptiveColumnsController.getHidingColumnsQueue().length;
13231319
}
13241320

1325-
protected _correctColumnWidths(resultWidths, visibleColumns) {
1321+
private updateColumnViewsFirstCellClasses(
1322+
oldHiddenColumns: Column[],
1323+
hiddenColumns: Column[],
1324+
): void {
1325+
if (oldHiddenColumns.length !== hiddenColumns.length) {
1326+
COLUMN_VIEWS.forEach((viewName) => {
1327+
const view = this.getView(viewName);
1328+
1329+
if (view?.isVisible() && view?.needToUpdateFirstCellClasses()) {
1330+
view.updateFirstCellClasses();
1331+
}
1332+
});
1333+
}
1334+
}
1335+
1336+
protected _correctColumnWidths(resultWidths: (number | string | undefined)[], visibleColumns: Column[]): boolean {
13261337
const adaptiveController = this._adaptiveColumnsController;
13271338
const oldHiddenColumns = adaptiveController.getHiddenColumns();
13281339
const hidingColumnsQueue = adaptiveController.updateHidingQueue(this._columnsController.getColumns());
@@ -1335,6 +1346,8 @@ const resizing = (Base: ModuleType<ResizingController>) => class AdaptivityResiz
13351346
}
13361347
}
13371348

1349+
this.updateColumnViewsFirstCellClasses(oldHiddenColumns, hiddenColumns);
1350+
13381351
!hiddenColumns.length && adaptiveController.collapseAdaptiveDetailRow();
13391352

13401353
return super._correctColumnWidths.apply(this, arguments as any);

packages/devextreme/js/__internal/grids/grid_core/column_headers/m_column_headers.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -359,14 +359,15 @@ export class ColumnHeadersView extends ColumnContextMenuMixin(ColumnsView) {
359359
const { column } = options;
360360
// @ts-expect-error
361361
const $cellElement = super._createCell.apply(this, arguments);
362+
const showColumnLines = this.option('showColumnLines');
362363

363364
if (options.rowType !== 'header') {
364365
return $cellElement;
365366
}
366367

367368
const rowCount = this.getRowCount();
368369

369-
if (rowCount > 1) {
370+
if (!showColumnLines && rowCount > 1) {
370371
this.toggleFirstCellClass(
371372
$cellElement,
372373
this._columnsController.isFirstColumn(column, options.rowIndex),
@@ -474,13 +475,6 @@ export class ColumnHeadersView extends ColumnContextMenuMixin(ColumnsView) {
474475
return returnAll ? $indicatorsContainer : $indicatorsContainer.filter(`:not(.${VISIBILITY_HIDDEN_CLASS})`);
475476
}
476477

477-
protected needToUpdateFirstCellClasses(): boolean {
478-
const showColumnLines = this.option('showColumnLines');
479-
const rowCount = this.getRowCount();
480-
481-
return (!showColumnLines && rowCount > 1) || super.needToUpdateFirstCellClasses();
482-
}
483-
484478
/**
485479
* @extended: tree_list/selection
486480
*/

packages/devextreme/js/__internal/grids/grid_core/views/m_columns_view.ts

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -733,30 +733,6 @@ export class ColumnsView extends ColumnStateMixin(modules.View) {
733733
$cell?.toggleClass(this.addWidgetPrefix(CLASSES.firstCell), isFirstValue);
734734
}
735735

736-
protected needToUpdateFirstCellClasses(): boolean {
737-
const hasHidingColumnsQueue = !!this._adaptiveColumnsController
738-
?.getHidingColumnsQueue()?.length;
739-
740-
return hasHidingColumnsQueue;
741-
}
742-
743-
protected updateFirstCellClasses(): void {
744-
const rows = this._getRows();
745-
746-
this.removeFirstCellClasses();
747-
748-
rows.forEach((row, index) => {
749-
const rowIndex = row.rowType === 'header' ? index : null;
750-
const firstColumn = this._columnsController.getFirstColumn(rowIndex);
751-
752-
if (firstColumn) {
753-
const $cell = this._getCellElement(index, `index:${firstColumn.index}`);
754-
755-
this.toggleFirstCellClass($cell, true);
756-
}
757-
});
758-
}
759-
760736
/**
761737
* @extended: column_fixing, filter_row, row_dragging, virtual_columns
762738
*/
@@ -767,10 +743,6 @@ export class ColumnsView extends ColumnStateMixin(modules.View) {
767743
this._scrollLeft = 0;
768744
this.scrollTo({ left: scrollLeft });
769745
}
770-
771-
if (this.needToUpdateFirstCellClasses()) {
772-
this.updateFirstCellClasses();
773-
}
774746
}
775747

776748
/**
@@ -1543,4 +1515,28 @@ export class ColumnsView extends ColumnStateMixin(modules.View) {
15431515
public renderDragCellContent($dragContainer: dxElementWrapper, column: Column): void {
15441516
$dragContainer.text(column.caption ?? '');
15451517
}
1518+
1519+
public needToUpdateFirstCellClasses(): boolean {
1520+
const hasHidingColumnsQueue = !!this._adaptiveColumnsController
1521+
?.getHidingColumnsQueue()?.length;
1522+
1523+
return hasHidingColumnsQueue;
1524+
}
1525+
1526+
public updateFirstCellClasses(): void {
1527+
const rows = this._getRows();
1528+
1529+
this.removeFirstCellClasses();
1530+
1531+
rows.forEach((row, index) => {
1532+
const rowIndex = row.rowType === 'header' ? index : null;
1533+
const firstColumn = this._columnsController.getFirstColumn(rowIndex);
1534+
1535+
if (firstColumn) {
1536+
const $cell = this._getCellElement(index, `index:${firstColumn.index}`);
1537+
1538+
this.toggleFirstCellClass($cell, true);
1539+
}
1540+
});
1541+
}
15461542
}

packages/devextreme/js/__internal/grids/grid_core/views/m_rows_view.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,10 +1187,6 @@ export class RowsView extends ColumnsView {
11871187

11881188
deferUpdate(() => {
11891189
this._updateScrollable();
1190-
1191-
if (this.needToUpdateFirstCellClasses()) {
1192-
this.updateFirstCellClasses();
1193-
}
11941190
});
11951191
});
11961192
}

0 commit comments

Comments
 (0)