devextreme
Version:
JavaScript/TypeScript Component Suite for Responsive Web Development
739 lines (738 loc) • 32.9 kB
JavaScript
/**
* DevExtreme (esm/__internal/grids/grid_core/views/grid_view.js)
* Version: 26.1.6
* Build date: Fri Oct 16 2026
*
* Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
import messageLocalization from "../../../../common/core/localization/message";
import domAdapter from "../../../../core/dom_adapter";
import $ from "../../../../core/renderer";
import browser from "../../../../core/utils/browser";
import {
deferRender,
deferUpdate
} from "../../../../core/utils/common";
import {
Deferred,
when
} from "../../../../core/utils/deferred";
import {
getBoundingRect
} from "../../../../core/utils/position";
import {
getHeight,
getWidth
} from "../../../../core/utils/size";
import {
setHeight
} from "../../../../core/utils/style";
import {
isDefined,
isNumeric,
isString
} from "../../../../core/utils/type";
import {
getWindow,
hasWindow
} from "../../../../core/utils/window";
import * as accessibility from "../../../../ui/shared/accessibility";
import {
A11yStatusContainerComponent
} from "../../../grids/grid_core/views/a11y_status_container_component";
import {
GROUP_COMMAND_COLUMN_NAME
} from "../columns_controller/const";
import gridCoreUtils from "../m_utils";
import modules from "../modules/modules";
import {
CLASSES
} from "./const";
const BORDERS_CLASS = "borders";
const IMPORTANT_MARGIN_CLASS = "important-margin";
const GRIDBASE_CONTAINER_CLASS = "dx-gridbase-container";
const GROUP_ROW_SELECTOR = `tr.${CLASSES.groupRow}`;
const HIDDEN_COLUMNS_WIDTH = "adaptiveHidden";
const VIEW_NAMES = ["columnsSeparatorView", "blockSeparatorView", "trackerView", "headerPanel", "columnHeadersView", "rowsView", "footerView", "columnChooserView", "filterPanelView", "pagerView", "draggingHeaderView", "contextMenuView", "headerFilterView", "filterBuilderView", "toastView", "aiPromptEditorView", "aiAssistantView"];
const E2E_ATTRIBUTES = {
a11yStatusContainer: "e2e-a11y-general-status-container"
};
const isPercentWidth = width => isString(width) && width.endsWith("%");
const isPixelWidth = width => isString(width) && width.endsWith("px");
const withWidthAt = (widths, index, width) => widths.map((columnWidth, columnIndex) => columnIndex === index ? width : columnWidth);
const restoreFocus = (focusedElement, selectionRange) => {
accessibility.hiddenFocus(focusedElement, true);
gridCoreUtils.setSelectionRange(focusedElement, selectionRange)
};
export class ResizingController extends modules.ViewController {
constructor() {
super(...arguments);
this.isMaxWidthSet = false
}
callbackNames() {
return ["resizeCompleted"]
}
init() {
this._prevContentMinHeight = null;
this._dataController = this.getController("data");
this.dataSourceController = this.getController("dataSource");
this._columnsController = this.getController("columns");
this._columnHeadersView = this.getView("columnHeadersView");
this.adaptiveColumnsController = this.getController("adaptiveColumns");
this._editorFactoryController = this.getController("editorFactory");
this._footerView = this.getView("footerView");
this._rowsView = this.getView("rowsView");
this._gridView = this.getView("gridView")
}
_initPostRenderHandlers() {
if (!this._refreshSizesHandler) {
const refreshSizesHandler = change => {
let resizeDeferred = Deferred().resolve(null);
const changeType = null === change || void 0 === change ? void 0 : change.changeType;
const isDelayed = null === change || void 0 === change ? void 0 : change.isDelayed;
const needFireContentReady = changeType && "updateSelection" !== changeType && "updateFocusedRow" !== changeType && "pageIndex" !== changeType && !isDelayed;
this._dataController.changed.remove(refreshSizesHandler);
if (this._checkSize()) {
resizeDeferred = this._refreshSizes(change)
}
if (needFireContentReady) {
when(resizeDeferred).done(() => {
this._setAriaLabel(change);
this.fireContentReadyAction()
})
}
};
this._refreshSizesHandler = refreshSizesHandler;
this._dataController.changed.add(() => {
this._dataController.changed.add(refreshSizesHandler)
})
}
}
_refreshSizes(e) {
const changeType = null === e || void 0 === e ? void 0 : e.changeType;
const isDelayed = null === e || void 0 === e ? void 0 : e.isDelayed;
if (!e || void 0 !== changeType && ["refresh", "prepend", "append"].includes(changeType)) {
if (!isDelayed) {
return this.resize()
}
}
if ("update" === changeType) {
var _e$changeTypes;
if (!(null !== (_e$changeTypes = e.changeTypes) && void 0 !== _e$changeTypes && _e$changeTypes.length)) {
return Deferred().resolve(null)
}
const items = this._dataController.items();
const isHidingNoDataPanel = items.length <= 1 && "insert" === e.changeTypes[0];
const isShowingNoDataPanel = 0 === items.length && "remove" === e.changeTypes[0];
if (!isHidingNoDataPanel && !isShowingNoDataPanel && !e.needUpdateDimensions) {
const deferred = Deferred();
this._waitAsyncTemplates().done(() => {
deferUpdate(() => deferRender(() => deferUpdate(() => {
this._setScrollerSpacing();
this._rowsView.resize();
deferred.resolve()
})))
}).fail(deferred.reject);
return deferred
}
return this.resize()
}
return Deferred().resolve(null)
}
fireContentReadyAction() {
this.component._fireContentReadyAction()
}
_getWidgetAriaLabel() {
return "dxDataGrid-ariaDataGrid"
}
_setAriaLabel(e) {
var _this$_columnsControl;
const visibleColumns = null === (_this$_columnsControl = this._columnsController) || void 0 === _this$_columnsControl || null === (_this$_columnsControl = _this$_columnsControl._columns) || void 0 === _this$_columnsControl ? void 0 : _this$_columnsControl.filter(_ref => {
let {
visible: visible
} = _ref;
return !!visible
});
const columnCount = (null === visibleColumns || void 0 === visibleColumns ? void 0 : visibleColumns.length) ?? 0;
const totalItemsCount = Math.max(0, this.dataSourceController.totalItemsCount());
const widgetAriaLabel = this._getWidgetAriaLabel();
const widgetStatusText = messageLocalization.format(widgetAriaLabel, totalItemsCount, columnCount);
const expandableWidgetAriaLabel = messageLocalization.format(this._expandableWidgetAriaId);
const labelText = expandableWidgetAriaLabel ? `${widgetStatusText}. ${expandableWidgetAriaLabel}` : widgetStatusText;
const $ariaLabelElement = this.component.$element().children(".dx-gridbase-container");
this.component.setAria("label", labelText, $ariaLabelElement);
if (!(null !== e && void 0 !== e && e.isFirstRender)) {
this._gridView.setWidgetA11yStatusText(widgetStatusText)
}
}
_getBestFitWidths() {
var _widths;
const rowsView = this._rowsView;
const columnHeadersView = this._columnHeadersView;
let widths = rowsView.getColumnWidths();
if (!(null !== (_widths = widths) && void 0 !== _widths && _widths.length)) {
var _rowsView$getTableEle;
const headersTableElement = columnHeadersView.getTableElement();
columnHeadersView.setTableElement(null === (_rowsView$getTableEle = rowsView.getTableElement()) || void 0 === _rowsView$getTableEle ? void 0 : _rowsView$getTableEle.children(`.${CLASSES.headerBody}`));
widths = columnHeadersView.getColumnWidths();
columnHeadersView.setTableElement(headersTableElement)
}
return widths
}
_setVisibleWidths(visibleColumns, widths) {
const columnsController = this._columnsController;
columnsController.beginUpdate();
visibleColumns.forEach((column, index) => {
const columnId = columnsController.getColumnId(column);
columnsController.columnOption(columnId, "visibleWidth", widths[index])
});
columnsController.endUpdate()
}
_toggleBestFitModeForView(view, className, isBestFit) {
if (!(null !== view && void 0 !== view && view.isVisible())) {
return
}
const $rowsTables = this._rowsView.getTableElements();
const $viewTables = view.getTableElements();
$rowsTables.toArray().forEach((tableElement, index) => {
const $rowsTable = $(tableElement);
const $viewTable = $viewTables.eq(index);
if (null !== $viewTable && void 0 !== $viewTable && $viewTable.length) {
const $tableBody = isBestFit ? $viewTable.children("tbody").appendTo($rowsTable) : $rowsTable.children(`.${className}`).appendTo($viewTable);
$tableBody.toggleClass(className, isBestFit);
$tableBody.toggleClass(this.addWidgetPrefix("best-fit"), isBestFit)
}
})
}
_toggleBestFitMode(isBestFit) {
const $rowsTable = this._rowsView.getTableElement();
const $rowsFixedTable = this._rowsView.getTableElements().eq(1);
if (!$rowsTable) {
return
}
$rowsTable.css("tableLayout", isBestFit ? "auto" : "fixed");
$rowsTable.children("colgroup").css("display", isBestFit ? "none" : "");
$rowsFixedTable.find(GROUP_ROW_SELECTOR).toArray().forEach(item => {
$(item).css("display", isBestFit ? "none" : "")
});
$rowsFixedTable.toggleClass(this.addWidgetPrefix(CLASSES.tableFixed), !isBestFit);
this._toggleBestFitModeForView(this._columnHeadersView, CLASSES.headerBody, isBestFit);
this._toggleBestFitModeForView(this._footerView, CLASSES.footerBody, isBestFit);
if (this._needStretch()) {
$rowsTable.get(0).style.width = isBestFit ? "auto" : ""
}
}
_toggleContentMinHeight(value) {
const $contentElement = this._rowsView._findContentElement();
if (true === value) {
this._prevContentMinHeight = $contentElement.get(0).style.minHeight
}
if (isDefined(this._prevContentMinHeight)) {
$contentElement.css({
minHeight: value ? gridCoreUtils.getContentHeightLimit(browser) : this._prevContentMinHeight
})
}
}
setMaxWidth(value) {
this.isMaxWidthSet = true;
this.component.$element().css("maxWidth", value)
}
_clearMaxWidth() {
if (!this.isMaxWidthSet) {
return
}
this.isMaxWidthSet = false;
const element = this.component.$element().get(0);
if (element) {
element.style.maxWidth = ""
}
}
enableTemporaryBestFitMode() {
const $element = this.component.$element();
const focusedElement = domAdapter.getActiveElement($element.get(0));
const selectionRange = gridCoreUtils.getSelectionRange(focusedElement);
this._toggleBestFitMode(true);
return () => {
this._toggleBestFitMode(false);
if (focusedElement && focusedElement !== domAdapter.getActiveElement()) {
const isFocusOutsideWindow = getBoundingRect(focusedElement).bottom < 0;
if (!isFocusOutsideWindow) {
restoreFocus(focusedElement, selectionRange)
}
}
}
}
synchronizeColumns() {
const columnsController = this._columnsController;
const visibleColumns = columnsController.getVisibleColumns();
const columnAutoWidth = this.option("columnAutoWidth");
const hasUndefinedColumnWidth = visibleColumns.some(column => !isDefined(column.width));
const needBestFit = !!this._needBestFit() || visibleColumns.some(column => "auto" === column.width);
const hasMinWidth = visibleColumns.some(column => !!column.minWidth);
this._toggleContentMinHeight(this._hasHeight);
this._setVisibleWidths(visibleColumns, []);
const restoreAfterBestFitMode = needBestFit && this.enableTemporaryBestFitMode();
this._clearMaxWidth();
deferUpdate(() => {
let resultWidths = [];
if (needBestFit || hasMinWidth) {
resultWidths = this._getBestFitWidths()
}
visibleColumns.forEach((column, index) => {
if (needBestFit) {
const columnId = columnsController.getColumnId(column);
columnsController.columnOption(columnId, "bestFitWidth", resultWidths[index], true)
}
const {
width: width
} = column;
if ("auto" !== width) {
if (isDefined(width)) {
resultWidths[index] = isNumeric(width) || isPixelWidth(width) ? parseFloat(String(width)) : width
} else if (!columnAutoWidth) {
resultWidths[index] = void 0
}
}
});
if (restoreAfterBestFitMode) {
restoreAfterBestFitMode()
}
const isColumnWidthsCorrected = this._correctColumnWidths(resultWidths, visibleColumns);
if (columnAutoWidth) {
this.normalizeWidthsByExpandColumns(resultWidths, visibleColumns);
if (this._needStretch()) {
this._processStretch(resultWidths, visibleColumns)
}
}
deferRender(() => {
if (needBestFit || isColumnWidthsCorrected || hasUndefinedColumnWidth) {
this._setVisibleWidths(visibleColumns, resultWidths)
}
this._toggleContentMinHeight(false)
})
})
}
_needBestFit() {
return this.option("columnAutoWidth")
}
_needStretch() {
return this._columnsController.getVisibleColumns().some(c => "auto" === c.width && !c.command)
}
calculateFreeWidth(widths) {
const contentWidth = this._rowsView.contentWidth();
const totalWidth = this._getTotalWidth(widths, contentWidth);
return contentWidth - totalWidth
}
_getAverageColumnsWidth(resultWidths) {
const freeWidth = this.calculateFreeWidth(resultWidths);
const columnCountWithoutWidth = resultWidths.filter(width => void 0 === width).length;
return freeWidth / columnCountWithoutWidth
}
normalizeWidthsByExpandColumns(resultWidths, visibleColumns) {
const isExpandColumn = column => column.type === GROUP_COMMAND_COLUMN_NAME;
const lastExpandColumnIndex = visibleColumns.map(isExpandColumn).lastIndexOf(true);
const expandColumnWidth = lastExpandColumnIndex >= 0 ? resultWidths[lastExpandColumnIndex] : void 0;
if (!expandColumnWidth) {
return
}
visibleColumns.forEach((column, index) => {
if (isExpandColumn(column)) {
resultWidths[index] = expandColumnWidth
}
})
}
_correctColumnWidths(resultWidths, visibleColumns) {
let hasPercentWidth = false;
let hasAutoWidth = false;
let isColumnWidthsCorrected = false;
const hasWidth = this._hasWidth;
for (let index = 0; index < visibleColumns.length; index += 1) {
const column = visibleColumns[index];
const isHiddenColumn = "adaptiveHidden" === resultWidths[index];
let width = resultWidths[index];
const {
minWidth: minWidth
} = column;
if (minWidth && void 0 === width) {
width = this._getAverageColumnsWidth(resultWidths)
} else if (minWidth && isPercentWidth(width)) {
const freeWidth = this.calculateFreeWidth(withWidthAt(resultWidths, index, minWidth));
if (freeWidth < 0) {
width = -1
}
}
const realColumnWidth = this._getRealColumnWidth(index, withWidthAt(resultWidths, index, width));
if (minWidth && !isHiddenColumn && realColumnWidth < minWidth) {
resultWidths[index] = minWidth;
isColumnWidthsCorrected = true;
index = -1
}
if (!isDefined(column.width)) {
hasAutoWidth = true
}
if (isPercentWidth(column.width)) {
hasPercentWidth = true
}
}
if (!hasAutoWidth && resultWidths.length) {
const $rowsViewElement = this._rowsView.element();
const contentWidth = this._rowsView.contentWidth();
const scrollbarWidth = this._rowsView.getScrollbarWidth();
const totalWidth = this._getTotalWidth(resultWidths, contentWidth);
if (totalWidth < contentWidth) {
const lastColumnIndex = gridCoreUtils.getLastResizableColumnIndex(visibleColumns, resultWidths);
if (lastColumnIndex >= 0) {
resultWidths[lastColumnIndex] = "auto";
isColumnWidthsCorrected = true;
if (false === hasWidth && !hasPercentWidth) {
const borderWidth = gridCoreUtils.getComponentBorderWidth(this, $rowsViewElement);
this.setMaxWidth(totalWidth + scrollbarWidth + borderWidth)
}
}
}
}
return isColumnWidthsCorrected
}
_processStretch(resultSizes, visibleColumns) {
const groupSize = this._rowsView.contentWidth();
const tableSize = this._getTotalWidth(resultSizes, groupSize);
const unusedIndexes = {
length: 0
};
if (!resultSizes.length) {
return
}
visibleColumns.forEach((column, index) => {
if (column.width || "adaptiveHidden" === resultSizes[index]) {
unusedIndexes[index] = true;
unusedIndexes.length += 1
}
});
const diff = groupSize - tableSize;
const diffElement = Math.floor(diff / (resultSizes.length - unusedIndexes.length));
let onePixelElementsCount = diff - diffElement * (resultSizes.length - unusedIndexes.length);
if (diff >= 0) {
for (let i = 0; i < resultSizes.length; i += 1) {
if (unusedIndexes[i]) {
continue
}
resultSizes[i] += diffElement;
if (onePixelElementsCount > 0 && onePixelElementsCount < 1) {
resultSizes[i] += onePixelElementsCount;
onePixelElementsCount = 0
} else if (onePixelElementsCount > 0) {
resultSizes[i] = Number(resultSizes[i]) + 1;
onePixelElementsCount -= 1
}
}
}
}
_getRealColumnWidth(columnIndex, columnWidths, groupWidth) {
let ratio = 1;
const width = columnWidths[columnIndex];
if (!isPercentWidth(width)) {
return parseFloat(String(width))
}
const percentTotalWidth = columnWidths.reduce((sum, columnWidth, index) => {
if (!isPercentWidth(columnWidth)) {
return sum
}
return sum + parseFloat(String(columnWidth))
}, 0);
const pixelTotalWidth = columnWidths.reduce((sum, columnWidth) => {
if (!columnWidth || "adaptiveHidden" === columnWidth || isPercentWidth(columnWidth)) {
return sum
}
return sum + parseFloat(String(columnWidth))
}, 0);
const currentGroupWidth = groupWidth || this._rowsView.contentWidth();
const freeSpace = currentGroupWidth - pixelTotalWidth;
const percentTotalWidthInPixel = percentTotalWidth * currentGroupWidth / 100;
if (pixelTotalWidth > 0 && percentTotalWidthInPixel + pixelTotalWidth >= currentGroupWidth) {
ratio = percentTotalWidthInPixel > freeSpace ? freeSpace / percentTotalWidthInPixel : 1
}
return parseFloat(String(width)) * currentGroupWidth * ratio / 100
}
_getTotalWidth(widths, groupWidth) {
let result = 0;
for (let i = 0; i < widths.length; i += 1) {
const width = widths[i];
if (width && "adaptiveHidden" !== width) {
result += this._getRealColumnWidth(i, widths, groupWidth)
}
}
return Math.ceil(result)
}
_getGroupElement() {
return this.component.$element().children().get(0)
}
updateSize(rootElement) {
const $rootElement = $(rootElement);
const importantMarginClass = this.addWidgetPrefix("important-margin");
if (void 0 === this._hasHeight && $rootElement && $rootElement.is(":visible") && getWidth($rootElement)) {
const $groupElement = $rootElement.children(`.${this.getWidgetContainerClass()}`);
if ($groupElement.length) {
$groupElement.detach()
}
this._hasHeight = !!getHeight($rootElement);
const width = getWidth($rootElement);
$rootElement.addClass(importantMarginClass);
this._hasWidth = getWidth($rootElement) === width;
$rootElement.removeClass(importantMarginClass);
if ($groupElement.length) {
$groupElement.appendTo($rootElement)
}
}
}
publicMethods() {
return ["resize", "updateDimensions"]
}
_waitAsyncTemplates() {
var _this$_columnHeadersV, _this$_rowsView, _this$_footerView;
return when(null === (_this$_columnHeadersV = this._columnHeadersView) || void 0 === _this$_columnHeadersV ? void 0 : _this$_columnHeadersV.waitAsyncTemplates(true), null === (_this$_rowsView = this._rowsView) || void 0 === _this$_rowsView ? void 0 : _this$_rowsView.waitAsyncTemplates(true), null === (_this$_footerView = this._footerView) || void 0 === _this$_footerView ? void 0 : _this$_footerView.waitAsyncTemplates(true))
}
resize() {
if (this.component._requireResize) {
return Deferred().resolve()
}
const d = Deferred();
this._waitAsyncTemplates().done(() => {
when(this.updateDimensions()).done(d.resolve).fail(d.reject)
}).fail(d.reject);
const promise = d.promise();
return promise.done(() => {
this.resizeCompleted.fire()
})
}
updateDimensions(checkSize) {
this._initPostRenderHandlers();
if (!this._checkSize(checkSize)) {
return
}
const prevResult = this._resizeDeferred;
const result = Deferred();
this._resizeDeferred = result;
when(prevResult).always(() => {
deferRender(() => {
if (this._dataController.isLoaded()) {
this.synchronizeColumns()
}
this._resetGroupElementHeight();
deferUpdate(() => {
deferRender(() => {
deferUpdate(() => {
this._updateDimensionsCore()
})
})
})
}).done(result.resolve).fail(result.reject)
});
return result.promise()
}
_resetGroupElementHeight() {
const groupElement = this._getGroupElement();
const scrollable = this._rowsView.getScrollable();
if (null !== groupElement && void 0 !== groupElement && groupElement.style.height && !(null !== scrollable && void 0 !== scrollable && scrollable.scrollTop())) {
groupElement.style.height = ""
}
}
_checkSize(checkSize) {
const $rootElement = this.component.$element();
const isWidgetVisible = $rootElement.is(":visible");
const isGridSizeChanged = this._lastWidth !== getWidth($rootElement) || this._lastHeight !== getHeight($rootElement) || this._devicePixelRatio !== getWindow().devicePixelRatio;
return isWidgetVisible && (!checkSize || isGridSizeChanged)
}
_setScrollerSpacingCore() {
const vScrollbarWidth = this._rowsView.getScrollbarWidth();
const hScrollbarWidth = this._rowsView.getScrollbarWidth(true);
deferRender(() => {
var _this$_columnHeadersV2, _this$_footerView2;
null === (_this$_columnHeadersV2 = this._columnHeadersView) || void 0 === _this$_columnHeadersV2 || _this$_columnHeadersV2.setScrollerSpacing(vScrollbarWidth);
null === (_this$_footerView2 = this._footerView) || void 0 === _this$_footerView2 || _this$_footerView2.setScrollerSpacing(vScrollbarWidth);
this._rowsView.setScrollerSpacing(vScrollbarWidth, hScrollbarWidth)
})
}
_setScrollerSpacing() {
const scrollable = this._rowsView.getScrollable();
const isNativeScrolling = true === this.option("scrolling.useNative");
if (!scrollable || isNativeScrolling) {
deferRender(() => {
deferUpdate(() => {
this._setScrollerSpacingCore()
})
})
} else {
this._setScrollerSpacingCore()
}
}
_setAriaOwns() {
var _this$_columnHeadersV3, _this$_footerView3, _this$_rowsView2;
const headerTable = null === (_this$_columnHeadersV3 = this._columnHeadersView) || void 0 === _this$_columnHeadersV3 ? void 0 : _this$_columnHeadersV3.getTableElement();
const footerTable = null === (_this$_footerView3 = this._footerView) || void 0 === _this$_footerView3 ? void 0 : _this$_footerView3.getTableElement();
null === (_this$_rowsView2 = this._rowsView) || void 0 === _this$_rowsView2 || _this$_rowsView2.setAriaOwns(null === headerTable || void 0 === headerTable ? void 0 : headerTable.attr("id"), null === footerTable || void 0 === footerTable ? void 0 : footerTable.attr("id"))
}
_updateDimensionsCore() {
const dataController = this._dataController;
const rowsView = this._rowsView;
const $rootElement = this.component.$element();
const groupElement = this._getGroupElement();
const rootElementHeight = getHeight($rootElement);
const height = this.option("height") ?? $rootElement.get(0).style.height;
const isHeightSpecified = !!height && "auto" !== height;
const maxHeight = parseInt($rootElement.css("maxHeight"), 10);
const maxHeightHappened = maxHeight && rootElementHeight >= maxHeight;
const isMaxHeightApplied = groupElement && groupElement.scrollHeight === groupElement.offsetHeight;
this.updateSize($rootElement);
deferRender(() => {
const hasHeight = !!this._hasHeight || !!maxHeight || isHeightSpecified;
rowsView.hasHeight(hasHeight);
this._setAriaOwns();
if (maxHeightHappened && !isMaxHeightApplied) {
setHeight($(groupElement), maxHeight)
}
if (!dataController.isLoaded()) {
rowsView.setLoading(dataController.isLoading());
return
}
deferUpdate(() => {
var _this$_editorFactoryC;
this._updateLastSizes($rootElement);
this._setScrollerSpacing();
VIEW_NAMES.forEach(viewName => {
const view = this.getView(viewName);
if (view) {
view.resize()
}
});
null === (_this$_editorFactoryC = this._editorFactoryController) || void 0 === _this$_editorFactoryC || _this$_editorFactoryC.resize()
})
})
}
_updateLastSizes($rootElement) {
this._lastWidth = getWidth($rootElement);
this._lastHeight = getHeight($rootElement);
this._devicePixelRatio = getWindow().devicePixelRatio
}
optionChanged(args) {
switch (args.name) {
case "width":
case "height":
this.component._renderDimensions();
this.resize();
case "renderAsync":
args.handled = true;
return;
default:
super.optionChanged(args)
}
}
resetLastResizeTime() {}
}
export class SynchronizeScrollingController extends modules.ViewController {
_scrollChangedHandler(views, pos, viewName) {
for (const view of views) {
if (view && view.name !== viewName) {
view.scrollTo({
left: pos.left,
top: pos.top
})
}
}
}
init() {
const views = [this.getView("columnHeadersView"), this.getView("footerView"), this.getView("rowsView")];
for (const view of views) {
if (view) {
view.scrollChanged.add(this._scrollChangedHandler.bind(this, views))
}
}
}
}
export class GridView extends modules.View {
init() {
this._resizingController = this.getController("resizing");
this._dataController = this.getController("data")
}
_endUpdateCore() {
if (this.component._requireResize) {
this.component._requireResize = false;
this._resizingController.resize()
}
}
getView(name) {
return this.component._views[name]
}
element() {
return this._groupElement
}
optionChanged(args) {
if (isDefined(this._groupElement) && "showBorders" === args.name) {
this._groupElement.toggleClass(this.addWidgetPrefix("borders"), !!args.value);
args.handled = true
} else {
super.optionChanged(args)
}
}
_renderViews($groupElement) {
VIEW_NAMES.forEach(viewName => {
const view = this.getView(viewName);
if (view) {
view.render($groupElement)
}
})
}
_getTableRoleName() {
return "group"
}
render($rootElement) {
const isFirstRender = !this._groupElement;
const $groupElement = this._groupElement ?? $("<div>").addClass(this.getWidgetContainerClass());
$groupElement.addClass("dx-gridbase-container");
$groupElement.toggleClass(this.addWidgetPrefix("borders"), !!this.option("showBorders"));
this.setAria("role", "presentation", $rootElement);
this.component.setAria("role", this._getTableRoleName(), $groupElement);
this._rootElement = $rootElement || this._rootElement;
if (isFirstRender) {
this._groupElement = $groupElement;
if (hasWindow()) {
this._resizingController.updateSize($rootElement)
}
$groupElement.appendTo($rootElement)
}
if (!this._a11yGeneralStatusElement) {
this._a11yGeneralStatusElement = A11yStatusContainerComponent({});
this._a11yGeneralStatusElement.attr(E2E_ATTRIBUTES.a11yStatusContainer, "true");
$groupElement.append(this._a11yGeneralStatusElement)
}
this._renderViews($groupElement)
}
update() {
const $rootElement = this._rootElement;
const $groupElement = this._groupElement;
if ($rootElement && $groupElement) {
this._resizingController.resize();
if (this._dataController.isLoaded()) {
this._resizingController.fireContentReadyAction()
}
}
}
setWidgetA11yStatusText(statusText) {
var _this$_a11yGeneralSta;
null === (_this$_a11yGeneralSta = this._a11yGeneralStatusElement) || void 0 === _this$_a11yGeneralSta || _this$_a11yGeneralSta.text(statusText)
}
}
export const gridViewModule = {
defaultOptions: () => ({
showBorders: false,
renderAsync: false
}),
controllers: {
resizing: ResizingController,
synchronizeScrolling: SynchronizeScrollingController
},
views: {
gridView: GridView
},
VIEW_NAMES: VIEW_NAMES
};