UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

1,154 lines • 51.2 kB
/**
 * DevExtreme (cjs/__internal/grids/grid_core/views/columns_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/
 */
"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.normalizeWidth = exports.ColumnsView = void 0;
var _click = require("../../../../common/core/events/click");
var _events_engine = _interopRequireDefault(require("../../../../common/core/events/core/events_engine"));
var _double_click = require("../../../../common/core/events/double_click");
var _pointer = _interopRequireDefault(require("../../../../common/core/events/pointer"));
var _remove = require("../../../../common/core/events/remove");
var _dom_adapter = _interopRequireDefault(require("../../../../core/dom_adapter"));
var _element = require("../../../../core/element");
var _element_data = require("../../../../core/element_data");
var _guid = _interopRequireDefault(require("../../../../core/guid"));
var _renderer = _interopRequireDefault(require("../../../../core/renderer"));
var _browser = _interopRequireDefault(require("../../../../core/utils/browser"));
var _common = require("../../../../core/utils/common");
var _deferred = require("../../../../core/utils/deferred");
var _extend = require("../../../../core/utils/extend");
var _position = require("../../../../core/utils/position");
var _size = require("../../../../core/utils/size");
var _style = require("../../../../core/utils/style");
var _type = require("../../../../core/utils/type");
var _window = require("../../../../core/utils/window");
var _m_support = _interopRequireDefault(require("../../../core/utils/m_support"));
var _const = require("../../../grids/grid_core/column_fixing/const");
var _const2 = require("../../../grids/grid_core/column_headers/const");
var _column_state_mixin = require("../../../grids/grid_core/column_state_mixin/column_state_mixin");
var _const3 = require("../../../grids/grid_core/columns_controller/const");
var _const4 = require("../../../grids/grid_core/error_handling/const");
var _const5 = require("../../../grids/grid_core/filter_row/const");
var _m_utils = _interopRequireDefault(require("../../../grids/grid_core/m_utils"));
var _const6 = require("../../../grids/grid_core/master_detail/const");
var _modules = _interopRequireDefault(require("../../../grids/grid_core/modules/modules"));
var _constants = require("../../../ui/form/constants");
var _const7 = require("./const");
var _utils = require("./utils");

function _interopRequireDefault(e) {
    return e && e.__esModule ? e : {
        default: e
    }
}
const HIDDEN_COLUMNS_WIDTH = "0.0001px";
const CELL_HINT_VISIBLE = "dxCellHintVisible";
const appendElementTemplate = {
    render(options) {
        options.container.append(options.content)
    }
};
const getWidthStyle = width => {
    if ("auto" === width) {
        return ""
    }
    return (0, _type.isNumeric)(width) ? `${width}px` : width
};
const setCellWidth = (cell, column, width) => {
    const cellWidth = "auto" === column.width ? "" : width;
    cell.style.maxWidth = cellWidth;
    cell.style.width = cellWidth
};
const copyAttributes = (element, newElement) => {
    if (!element || !newElement) {
        return
    }
    const oldAttributes = element.attributes;
    const newAttributes = newElement.attributes;
    for (let i = 0; i < oldAttributes.length; i += 1) {
        const name = oldAttributes[i].nodeName;
        if (!newElement.hasAttribute(name)) {
            element.removeAttribute(name)
        }
    }
    for (const attribute of newAttributes) {
        element.setAttribute(attribute.nodeName, attribute.value)
    }
};
const isRenderTemplate = template => !!template && !!template.render && !(0, _type.isRenderer)(template);
const normalizeWidth = width => {
    if ("number" === typeof width) {
        return `${width.toFixed(3)}px`
    }
    if ("adaptiveHidden" === width) {
        return "0.0001px"
    }
    return width
};
exports.normalizeWidth = normalizeWidth;
class ColumnsView extends((0, _column_state_mixin.ColumnStateMixin)(_modules.default.View)) {
    init() {
        this._scrollLeft = void 0;
        this._columnsController = this.getController("columns");
        this._dataController = this.getController("data");
        this.adaptiveColumnsController = this.getController("adaptiveColumns");
        this._columnChooserController = this.getController("columnChooser");
        this._editorFactoryController = this.getController("editorFactory");
        this._selectionController = this.getController("selection");
        this._columnChooserView = this.getView("columnChooserView");
        this._delayedTemplates = [];
        this._templateDeferreds = new Set;
        this._templatesCache = {};
        this._templateTimeouts = new Set;
        this.createAction("onCellClick");
        this.createAction("onRowClick");
        this.createAction("onCellDblClick");
        this.createAction("onRowDblClick");
        this.createAction("onCellHoverChanged", {
            excludeValidators: ["disabled", "readOnly"]
        });
        this.createAction("onCellPrepared", {
            excludeValidators: ["disabled", "readOnly"],
            category: "rendering"
        });
        this.createAction("onRowPrepared", {
            excludeValidators: ["disabled", "readOnly"],
            category: "rendering",
            afterExecute: e => {
                this._afterRowPrepared(e)
            }
        });
        this._columnsController.columnsChanged.add(this._columnOptionChanged.bind(this));
        if (this._dataController) {
            this._dataController.changed.add(this._handleDataChanged.bind(this))
        }
    }
    dispose() {
        if ((0, _window.hasWindow)()) {
            var _this$_templateTimeou, _this$_templateTimeou2;
            const window = (0, _window.getWindow)();
            null === (_this$_templateTimeou = this._templateTimeouts) || void 0 === _this$_templateTimeou || _this$_templateTimeou.forEach(templateTimeout => window.clearTimeout(templateTimeout));
            null === (_this$_templateTimeou2 = this._templateTimeouts) || void 0 === _this$_templateTimeou2 || _this$_templateTimeou2.clear()
        }
    }
    optionChanged(args) {
        super.optionChanged(args);
        switch (args.name) {
            case "cellHintEnabled":
            case "onCellPrepared":
            case "onRowPrepared":
            case "onCellHoverChanged":
                this._invalidate(true, true);
                args.handled = true;
                break;
            case "keyboardNavigation":
                if ("keyboardNavigation.enabled" === args.fullName) {
                    this._invalidate(true, true)
                }
                args.handled = true
        }
    }
    _createScrollableOptions() {
        const scrollingOptions = this.option("scrolling");
        const useNativeScrolling = this.option("scrolling.useNative");
        const options = (0, _extend.extend)({}, scrollingOptions, {
            direction: "both",
            bounceEnabled: false,
            useKeyboard: false
        });
        if ("auto" === useNativeScrolling) {
            delete options.useNative;
            delete options.useSimulatedScrollbar
        } else {
            options.useNative = !!useNativeScrolling;
            options.useSimulatedScrollbar = !useNativeScrolling
        }
        return options
    }
    _updateCell($cell, parameters) {
        if (parameters.rowType) {
            this._cellPrepared($cell, parameters)
        }
    }
    _needToSetCellWidths() {
        return this.option("columnAutoWidth")
    }
    _createCell(options) {
        const {
            column: column
        } = options;
        const alignment = column.alignment ?? (0, _position.getDefaultAlignment)(this.option("rtlEnabled"));
        const needToSetCellWidths = this._needToSetCellWidths();
        const cell = _dom_adapter.default.createElement("td");
        cell.style.textAlign = alignment;
        const $cell = (0, _renderer.default)(cell);
        if (column.cssClass) {
            $cell.addClass(column.cssClass)
        }
        if (Array.isArray(column.elementAttr)) {
            column.elementAttr.forEach(_ref => {
                let {
                    name: name,
                    value: value
                } = _ref;
                $cell.attr(name, value)
            })
        }
        if ("expand" === column.command) {
            if ((0, _type.isDefined)(column.cssClass)) {
                $cell.addClass(column.cssClass)
            }
            $cell.addClass(this.addWidgetPrefix(_const7.CLASSES.groupSpace))
        }
        if ((0, _type.isDefined)(column.colspan) && column.colspan > 1) {
            $cell.attr("colSpan", column.colspan)
        } else if (!column.isBand && "auto" !== column.visibleWidth && needToSetCellWidths) {
            const minWidth = column.minWidth || column.width;
            if (minWidth) {
                cell.style.minWidth = getWidthStyle(minWidth)
            }
            if (column.width) {
                setCellWidth(cell, column, getWidthStyle(column.width))
            }
        }
        return $cell
    }
    _createRow(rowObject) {
        let tagName = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : "tr";
        const $element = (0, _renderer.default)(`<${tagName}>`).addClass(_const7.CLASSES.row);
        if ("tr" === tagName) {
            this.setAria("role", "row", $element)
        }
        return $element
    }
    _isAltRow(row) {
        return row && (0, _type.isDefined)(row.dataIndex) && row.dataIndex % 2 === 1
    }
    _createTable(columns, isAppend) {
        const $table = (0, _renderer.default)("<table>").addClass(this.addWidgetPrefix(_const7.CLASSES.table)).addClass(this.addWidgetPrefix(_const7.CLASSES.tableFixed));
        if (columns && !isAppend) {
            $table.attr("id", `dx-${new _guid.default}`).append(this._createColGroup(columns));
            if (_browser.default.safari) {
                $table.append((0, _renderer.default)("<thead>").append("<tr>"))
            }
            this.setAria("role", "presentation", $table)
        } else {
            this.setAria("hidden", true, $table)
        }
        this.setAria("role", "presentation", (0, _renderer.default)("<tbody>").appendTo($table));
        if (isAppend) {
            return $table
        }
        if (_browser.default.mozilla) {
            _events_engine.default.on($table, "mousedown", "td", e => {
                if (e.ctrlKey) {
                    e.preventDefault()
                }
            })
        }
        if (this.option("cellHintEnabled")) {
            _events_engine.default.on($table, "mousemove", `.${_const7.CLASSES.row} > td`, this.createAction(args => {
                var _rowOptions$cells;
                const e = args.event;
                const $element = (0, _renderer.default)(e.target);
                const $cell = (0, _renderer.default)(e.currentTarget);
                const $row = $cell.parent();
                const visibleColumns = this._columnsController.getVisibleColumns();
                const rowOptions = $row.data("options");
                const columnIndex = $cell.index();
                const cellOptions = null === rowOptions || void 0 === rowOptions || null === (_rowOptions$cells = rowOptions.cells) || void 0 === _rowOptions$cells ? void 0 : _rowOptions$cells[columnIndex];
                const column = cellOptions ? cellOptions.column : visibleColumns[columnIndex];
                const isHeaderRow = $row.hasClass(_const2.CLASSES.headerRow);
                const isDataRow = $row.hasClass(_const7.CLASSES.dataRow);
                const isMasterDetailRow = $row.hasClass(_const6.CLASSES.detailRow);
                const isGroupRow = $row.hasClass(_const7.CLASSES.groupRow);
                const isFilterRow = $row.hasClass(this.addWidgetPrefix(_const5.CLASSES.filterRow));
                const hasCellTemplate = !column || column.cellTemplate;
                const hasHeaderCellTemplate = !column || column.headerCellTemplate;
                const hasGroupCellTemplate = !column || column.groupIndex && column.groupCellTemplate;
                const isEditing = !!(null !== rowOptions && void 0 !== rowOptions && rowOptions.isEditing) || !!(null !== cellOptions && void 0 !== cellOptions && cellOptions.isEditing);
                const hasEditor = isEditing || (null === column || void 0 === column ? void 0 : column.showEditorAlways);
                const isDataRowWithTemplate = isDataRow && hasCellTemplate;
                const isEditorShown = isDataRow && cellOptions && hasEditor;
                const isHeaderRowWithTemplate = isHeaderRow && hasHeaderCellTemplate;
                const isGroupCellWithTemplate = isGroupRow && hasGroupCellTemplate;
                const shouldShowHint = !isMasterDetailRow && !isFilterRow && !isEditorShown && !isDataRowWithTemplate && !isHeaderRowWithTemplate && !isGroupCellWithTemplate;
                if (shouldShowHint) {
                    this._setCellTitleAttribute($element, isHeaderRow)
                }
            }))
        }
        const getOptions = event => {
            var _rowOptions$cells2;
            const $cell = (0, _renderer.default)(event.currentTarget);
            const $fieldItemContent = (0, _renderer.default)(event.target).closest(`.${_constants.FIELD_ITEM_CONTENT_CLASS}`);
            const $row = $cell.parent();
            const rowOptions = $row.data("options");
            const options = null === rowOptions || void 0 === rowOptions || null === (_rowOptions$cells2 = rowOptions.cells) || void 0 === _rowOptions$cells2 ? void 0 : _rowOptions$cells2[$cell.index()];
            if (!$cell.closest("table").is(event.delegateTarget)) {
                return
            }
            const resultOptions = (0, _extend.extend)({}, options, {
                cellElement: (0, _element.getPublicElement)($cell),
                event: event,
                eventType: event.type
            });
            resultOptions.rowIndex = this.getRowIndex($row);
            if ($fieldItemContent.length) {
                const formItemOptions = $fieldItemContent.data("dx-form-item");
                if (formItemOptions.column) {
                    resultOptions.column = formItemOptions.column;
                    resultOptions.columnIndex = this._columnsController.getVisibleIndex(resultOptions.column.index)
                }
            }
            return resultOptions
        };
        _events_engine.default.on($table, "mouseover", `.${_const7.CLASSES.row} > td`, e => {
            const options = getOptions(e);
            if (options) {
                this.executeAction("onCellHoverChanged", options)
            }
        });
        _events_engine.default.on($table, "mouseout", `.${_const7.CLASSES.row} > td`, e => {
            const options = getOptions(e);
            if (options) {
                this.executeAction("onCellHoverChanged", options)
            }
        });
        _events_engine.default.on($table, _click.name, `.${_const7.CLASSES.row} > td`, e => {
            const options = getOptions(e);
            if (options) {
                this.executeAction("onCellClick", options)
            }
        });
        _events_engine.default.on($table, _double_click.name, `.${_const7.CLASSES.row} > td`, e => {
            const options = getOptions(e);
            if (options) {
                this.executeAction("onCellDblClick", options)
            }
        });
        this.subscribeToRowEvents($table);
        return $table
    }
    subscribeToRowEvents($table) {
        let touchTargets = null;
        let timeoutId;

        function clearTouchTargets(timeout) {
            return setTimeout(() => {
                touchTargets = null
            }, timeout)
        }
        _events_engine.default.on($table, "touchstart touchend", `.${_const7.CLASSES.row}`, e => {
            clearTimeout(timeoutId);
            if ("touchstart" === e.type) {
                touchTargets = {
                    target: e.target,
                    currentTarget: e.currentTarget
                };
                timeoutId = clearTouchTargets(1e3)
            } else {
                timeoutId = clearTouchTargets()
            }
        });
        _events_engine.default.on($table, [_click.name, _double_click.name, _pointer.default.down].join(" "), `.${_const7.CLASSES.row}`, this.createAction(e => {
            const {
                event: event
            } = e;
            if (!_m_utils.default.isElementInCurrentGrid(this, (0, _renderer.default)(event.target))) {
                return
            }
            if (touchTargets) {
                event.target = touchTargets.target;
                event.currentTarget = touchTargets.currentTarget
            }
            if (!(0, _renderer.default)(event.target).closest("a").length) {
                e.rowIndex = this.getRowIndex(event.currentTarget);
                if (e.rowIndex >= 0) {
                    e.rowElement = (0, _element.getPublicElement)((0, _renderer.default)(event.currentTarget));
                    e.columns = this.getColumns();
                    if (event.type === _pointer.default.down) {
                        this._rowPointerDown(e)
                    } else if (event.type === _click.name) {
                        this._rowClick(e)
                    } else {
                        this._rowDblClick(e)
                    }
                }
            }
        }))
    }
    _setCellTitleAttribute($cell, isHeaderRow) {
        if ($cell.data(CELL_HINT_VISIBLE)) {
            $cell.removeAttr("title");
            $cell.data(CELL_HINT_VISIBLE, false)
        }
        let $cellContent = $cell;
        const headerContentClass = this.addWidgetPrefix(_const2.CLASSES.cellContent);
        if (isHeaderRow && !$cell.hasClass(headerContentClass)) {
            const $headerContent = $cell.find(`.${headerContentClass}`);
            $cellContent = $headerContent.length ? $headerContent : $cellContent
        }
        const hasWidthOverflow = $cellContent[0].scrollWidth - $cellContent[0].clientWidth > 0;
        if (!hasWidthOverflow || (0, _type.isDefined)($cell.attr("title"))) {
            return
        }
        const hintText = $cellContent.text() || $cell.text();
        $cell.attr("title", hintText);
        $cell.data(CELL_HINT_VISIBLE, true)
    }
    _rowPointerDown(e) {}
    _rowClick(e) {}
    _rowDblClick(e) {}
    _createColGroup(columns) {
        const colgroupElement = (0, _renderer.default)("<colgroup>");
        for (const column of columns) {
            const colspan = column.colspan || 1;
            for (let j = 0; j < colspan; j += 1) {
                colgroupElement.append(this._createCol(column))
            }
        }
        return colgroupElement
    }
    _createCol(column) {
        let width = column.visibleWidth || column.width;
        if ("adaptiveHidden" === width) {
            width = "0.0001px"
        }
        const col = (0, _renderer.default)("<col>");
        (0, _style.setWidth)(col, width);
        return col
    }
    renderDelayedTemplates(change) {
        const delayedTemplates = this._delayedTemplates;
        const syncTemplates = delayedTemplates.filter(template => !template.async);
        const asyncTemplates = delayedTemplates.filter(template => template.async);
        this._delayedTemplates = [];
        this._renderDelayedTemplatesCore(syncTemplates, false, change);
        this._renderDelayedTemplatesCoreAsync(asyncTemplates)
    }
    _renderDelayedTemplatesCoreAsync(templates) {
        if (templates.length) {
            const templateTimeout = (0, _window.getWindow)().setTimeout(() => {
                this._templateTimeouts.delete(templateTimeout);
                this._renderDelayedTemplatesCore(templates, true)
            });
            this._templateTimeouts.add(templateTimeout)
        }
    }
    _renderDelayedTemplatesCore(templates, isAsync, change) {
        const date = new Date;
        while (templates.length) {
            const templateParameters = templates.shift();
            if (!templateParameters) {
                break
            }
            const {
                options: options
            } = templateParameters;
            const doc = _dom_adapter.default.getRootNode((0, _renderer.default)(options.container).get(0));
            const needWaitAsyncTemplates = this.needWaitAsyncTemplates();
            if (!isAsync || (0, _renderer.default)(options.container).closest(doc).length || needWaitAsyncTemplates) {
                if (change) {
                    options.change = change
                }
                templateParameters.template.render(options)
            }
            if (isAsync && new Date - date > 30) {
                this._renderDelayedTemplatesCoreAsync(templates);
                break
            }
        }
        if (!templates.length && this._delayedTemplates.length) {
            this.renderDelayedTemplates()
        }
    }
    _processTemplate(template, options) {
        if (isRenderTemplate(template)) {
            return {
                allowRenderToDetachedContainer: template.allowRenderToDetachedContainer,
                render(templateOptions) {
                    var _templateOptions$defe;
                    template.render(templateOptions.container, templateOptions.model, templateOptions.change);
                    null === (_templateOptions$defe = templateOptions.deferred) || void 0 === _templateOptions$defe || _templateOptions$defe.resolve()
                }
            }
        }
        if ((0, _type.isFunction)(template)) {
            return {
                render(templateOptions) {
                    var _templateOptions$defe2;
                    const renderedTemplate = template((0, _element.getPublicElement)(templateOptions.container), templateOptions.model, templateOptions.change);
                    if (renderedTemplate && (renderedTemplate.nodeType || (0, _type.isRenderer)(renderedTemplate))) {
                        templateOptions.container.append(renderedTemplate)
                    }
                    null === (_templateOptions$defe2 = templateOptions.deferred) || void 0 === _templateOptions$defe2 || _templateOptions$defe2.resolve()
                }
            }
        }
        const templateID = (0, _type.isString)(template) ? template : (0, _renderer.default)(template).attr("id");
        if (!templateID) {
            return this.getTemplate(template)
        }
        if (!this._templatesCache[templateID]) {
            this._templatesCache[templateID] = this.getTemplate(template)
        }
        return this._templatesCache[templateID]
    }
    renderTemplate(container, template, options, allowRenderToDetachedContainer, change) {
        const renderingTemplate = this._processTemplate(template, options);
        const templateDeferred = (0, _deferred.Deferred)();
        const templateOptions = {
            container: container,
            model: options,
            deferred: templateDeferred,
            onRendered: () => {
                if (this.isDisposed()) {
                    templateDeferred.reject()
                } else {
                    templateDeferred.resolve()
                }
            }
        };
        if (renderingTemplate) {
            options.component = this.component;
            const {
                column: column,
                rowType: rowType
            } = options;
            const isDataRow = "data" === rowType;
            const isFilterRow = "filter" === rowType;
            const isCommandOrEditorCell = !!(null !== column && void 0 !== column && column.command) || !!(null !== column && void 0 !== column && column.showEditorAlways);
            const isAsyncColumn = isDataRow && !!(null !== column && void 0 !== column && column.renderAsync);
            const isAsyncByDefault = isDataRow && false !== (null === column || void 0 === column ? void 0 : column.renderAsync) && isCommandOrEditorCell;
            const isAsyncByGrid = !!this.option("renderAsync") && (isAsyncByDefault || isFilterRow);
            const columnAsync = !!column && (isAsyncColumn || isAsyncByGrid);
            const async = options.renderAsync ?? columnAsync;
            const canRenderToDetachedContainer = !!renderingTemplate.allowRenderToDetachedContainer || !!allowRenderToDetachedContainer;
            if (canRenderToDetachedContainer && !async) {
                renderingTemplate.render(templateOptions)
            } else {
                this._delayedTemplates.push({
                    template: renderingTemplate,
                    options: templateOptions,
                    async: async
                })
            }
            this._templateDeferreds.add(templateDeferred);
            _events_engine.default.on(container, _remove.removeEvent, () => {
                templateDeferred.resolve()
            })
        } else {
            templateDeferred.reject()
        }
        return templateDeferred.promise().always(() => {
            this._templateDeferreds.delete(templateDeferred)
        })
    }
    _getBodies(tableElement) {
        return (0, _renderer.default)(tableElement).children("tbody").not(`.${_const7.CLASSES.headerBody}`).not(`.${_const7.CLASSES.footerBody}`)
    }
    _needWrapRow($tableElement) {
        var _this$_getBodies;
        const hasRowTemplate = !!this.option().rowTemplate;
        return hasRowTemplate && !!(null !== (_this$_getBodies = this._getBodies($tableElement)) && void 0 !== _this$_getBodies && _this$_getBodies.filter(`.${_const7.CLASSES.row}`).length)
    }
    _wrapRowIfNeed($table, $row, isRefreshing) {
        const $tableElement = isRefreshing ? $table || this._tableElement : this._tableElement || $table;
        const needWrapRow = this._needWrapRow($tableElement);
        if (needWrapRow) {
            const $tbody = (0, _renderer.default)("<tbody>").addClass($row.attr("class") ?? "");
            this.setAria("role", "presentation", $tbody);
            return $tbody.append($row)
        }
        return $row
    }
    _appendRow($table, $row) {
        let appendTemplate = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : appendElementTemplate;
        appendTemplate.render({
            content: $row,
            container: $table
        })
    }
    removeFirstCellClasses() {
        var _this$_tableElement;
        const firstCellClass = this.addWidgetPrefix(_const7.CLASSES.firstCell);
        null === (_this$_tableElement = this._tableElement) || void 0 === _this$_tableElement || _this$_tableElement.find(`.${firstCellClass}`).removeClass(firstCellClass)
    }
    toggleFirstCellClass($cell, isFirstValue) {
        null === $cell || void 0 === $cell || $cell.toggleClass(this.addWidgetPrefix(_const7.CLASSES.firstCell), isFirstValue)
    }
    _resizeCore() {
        this.updateScrollLeftPosition()
    }
    _renderCore(e) {
        const $root = this.element().parent();
        if (!$root || $root.parent().length) {
            this.renderDelayedTemplates(e)
        }
        return (0, _deferred.Deferred)().resolve()
    }
    _renderTable() {
        let options = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
        options.columns = this._columnsController.getVisibleColumns();
        const changeType = options.change && options.change.changeType;
        const $table = this._createTable(options.columns, "append" === changeType || "prepend" === changeType || "update" === changeType);
        this._renderRows($table, options);
        return $table
    }
    _renderRows($table, options) {
        var _options$change, _options$change2;
        const rows = this._getRows(options.change);
        const columnIndices = (null === (_options$change = options.change) || void 0 === _options$change ? void 0 : _options$change.columnIndices) ?? [];
        const changeTypes = (null === (_options$change2 = options.change) || void 0 === _options$change2 ? void 0 : _options$change2.changeTypes) ?? [];
        for (let i = 0; i < rows.length; i += 1) {
            this._renderRow($table, (0, _extend.extend)({
                row: rows[i],
                columnIndices: columnIndices[i],
                changeType: changeTypes[i]
            }, options))
        }
    }
    _renderRow($table, options) {
        if (!options.columnIndices) {
            options.row.cells = []
        }
        const $row = this._createRow(options.row);
        const $wrappedRow = this._wrapRowIfNeed($table, $row);
        if ("remove" !== options.changeType) {
            this._renderCells($row, options)
        }
        this._appendRow($table, $wrappedRow);
        const rowOptions = (0, _extend.extend)({
            columns: options.columns
        }, options.row);
        this._addWatchMethod(rowOptions, options.row);
        this._rowPrepared($wrappedRow, rowOptions, options.row)
    }
    _needRenderCell(columnIndex, columnIndices) {
        return !columnIndices || columnIndices.includes(columnIndex)
    }
    _renderCells($row, options) {
        let columnIndex = 0;
        const {
            row: row
        } = options;
        const {
            columns: columns
        } = options;
        for (let i = 0; i < columns.length; i += 1) {
            if (this._needRenderCell(i, options.columnIndices)) {
                var _row$values, _row$oldValues;
                this._renderCell($row, (0, _extend.extend)({
                    column: columns[i],
                    columnIndex: columnIndex,
                    value: null === (_row$values = row.values) || void 0 === _row$values ? void 0 : _row$values[columnIndex],
                    oldValue: null === (_row$oldValues = row.oldValues) || void 0 === _row$oldValues ? void 0 : _row$oldValues[columnIndex]
                }, options))
            }
            const {
                colspan: colspan
            } = columns[i];
            if ((0, _type.isDefined)(colspan) && colspan > 1) {
                columnIndex += colspan
            } else {
                columnIndex += 1
            }
        }
    }
    _updateCells($rowElement, $newRowElement, columnIndices, options) {
        var _options$node;
        const $cells = $rowElement.children();
        const $newCells = $newRowElement.children();
        const highlightChanges = this.option("highlightChanges");
        const cellUpdatedClass = this.addWidgetPrefix(_const7.CLASSES.cellUpdatedAnimation);
        if (null !== options && void 0 !== options && null !== (_options$node = options.node) && void 0 !== _options$node && _options$node.hasChildren) {
            $cells.toArray().forEach(cell => {
                this.setAria("expanded", options.isExpanded, (0, _renderer.default)(cell))
            })
        }
        columnIndices.forEach((columnIndex, index) => {
            const $cell = $cells.eq(columnIndex);
            const $newCell = $newCells.eq(index);
            $cell.replaceWith($newCell);
            if (highlightChanges && !$newCell.hasClass(_const3.CLASSES.commandExpand)) {
                $newCell.addClass(cellUpdatedClass)
            }
        });
        copyAttributes($rowElement.get(0), $newRowElement.get(0))
    }
    _setCellAriaAttributes($cell, cellOptions, options) {
        var _row$node;
        const {
            row: row
        } = options;
        const isFreeSpaceRow = "freeSpace" === cellOptions.rowType;
        const isGroupRow = "group" === cellOptions.rowType;
        const rowHasChildren = null === row || void 0 === row || null === (_row$node = row.node) || void 0 === _row$node ? void 0 : _row$node.hasChildren;
        if (isFreeSpaceRow) {
            return
        }
        this.setAria("role", "gridcell", $cell);
        if (rowHasChildren) {
            this.setAria("expanded", row.isExpanded, $cell)
        }
        const columnIndexOffset = this._columnsController.getColumnIndexOffset();
        const ariaColIndex = isGroupRow ? cellOptions.columnIndex + 1 : cellOptions.columnIndex + columnIndexOffset + 1;
        this.setAria("colindex", ariaColIndex, $cell)
    }
    _renderCell($row, options) {
        const cellOptions = this._getCellOptions(options);
        if (options.columnIndices) {
            if (options.row.cells) {
                const cellIndex = options.row.cells.findIndex(cell => cell.columnIndex === cellOptions.columnIndex);
                options.row.cells[cellIndex] = cellOptions
            }
        } else {
            options.row.cells.push(cellOptions)
        }
        const $cell = this._createCell(cellOptions);
        this._setCellAriaAttributes($cell, cellOptions, options);
        this._renderCellContent($cell, cellOptions, options);
        $row.get(0).appendChild($cell.get(0));
        return $cell
    }
    _renderCellContent($cell, options, renderOptions) {
        const template = this._getCellTemplate(options);
        (0, _deferred.when)(!template || this.renderTemplate($cell, template, options, void 0, renderOptions.change)).done(() => {
            this._updateCell($cell, options)
        })
    }
    _getCellTemplate(options) {
        return
    }
    _getRows(change) {
        return []
    }
    _getCellOptions(options) {
        const cellOptions = {
            column: options.column,
            columnIndex: options.columnIndex,
            rowType: options.row.rowType,
            rowIndex: options.row.rowIndex,
            isAltRow: this._isAltRow(options.row)
        };
        this._addWatchMethod(cellOptions);
        return cellOptions
    }
    _addWatchMethod(options) {
        let source = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : options;
        if (!this.option("repaintChangesOnly")) {
            return
        }
        const watchers = [];
        source.watch ?? (source.watch = (getter, updateValueFunc, updateRowFunc) => {
            let oldValue = getter(source.data);
            const watcher = row => {
                if (row && updateRowFunc) {
                    updateRowFunc(row)
                }
                const newValue = getter(source.data);
                if (JSON.stringify(oldValue) !== JSON.stringify(newValue)) {
                    if (row) {
                        updateValueFunc(newValue)
                    }
                    oldValue = newValue
                }
            };
            watchers.push(watcher);
            return () => {
                const index = watchers.indexOf(watcher);
                if (index >= 0) {
                    watchers.splice(index, 1)
                }
            }
        });
        source.update ?? (source.update = function(row, keepRow) {
            if (row) {
                options.data = row.data;
                this.data = options.data;
                options.rowIndex = row.rowIndex;
                this.rowIndex = options.rowIndex;
                options.dataIndex = row.dataIndex;
                this.dataIndex = options.dataIndex;
                options.isExpanded = row.isExpanded;
                this.isExpanded = options.isExpanded;
                if (options.row && !keepRow) {
                    options.row = row
                }
            }
            watchers.forEach(watcher => {
                watcher(row)
            })
        });
        if (source !== options) {
            options.watch = source.watch.bind(source)
        }
        return options
    }
    _cellPrepared(cell, options) {
        options.cellElement = (0, _element.getPublicElement)((0, _renderer.default)(cell));
        this.executeAction("onCellPrepared", options)
    }
    _rowPrepared($row, options, row) {
        (0, _element_data.data)($row.get(0), "options", options);
        options.rowElement = (0, _element.getPublicElement)($row);
        this.executeAction("onRowPrepared", options)
    }
    _columnOptionChanged(_ref2) {
        let {
            optionNames: optionNames
        } = _ref2;
        if (_m_utils.default.checkChanges(optionNames, ["width", "visibleWidth"])) {
            const visibleColumns = this._columnsController.getVisibleColumns();
            const widths = visibleColumns.map(column => column.visibleWidth || column.width);
            this.setColumnWidths({
                widths: widths,
                optionNames: optionNames
            });
            return
        }
        if (!this._requireReady) {
            this.render()
        }
    }
    getCellIndex($cell, rowIndex) {
        const cellIndex = $cell.length ? $cell[0].cellIndex : -1;
        return cellIndex
    }
    getTableElements() {
        return this._tableElement ?? (0, _renderer.default)()
    }
    getTableElement(isFixedTableRendering) {
        return this._tableElement
    }
    setTableElement(tableElement, isFixedTableRendering) {
        this._tableElement = tableElement
    }
    _afterRowPrepared(e) {}
    _handleDataChanged(e) {}
    callbackNames() {
        return ["scrollChanged"]
    }
    updateScrollLeftPosition() {
        const scrollLeft = this._scrollLeft;
        if ((0, _type.isDefined)(scrollLeft)) {
            this._scrollLeft = 0;
            this.scrollTo({
                left: scrollLeft
            })
        }
    }
    scrollTo(pos) {
        const $element = this.element();
        const $scrollContainer = null === $element || void 0 === $element ? void 0 : $element.children(`.${this.addWidgetPrefix(_const7.CLASSES.scrollContainer)}`).not(`.${this.addWidgetPrefix(_const.CLASSES.contentFixed)}`);
        if ((0, _type.isDefined)(pos) && (0, _type.isDefined)(pos.left) && this._scrollLeft !== pos.left) {
            this._scrollLeft = pos.left;
            null === $scrollContainer || void 0 === $scrollContainer || $scrollContainer.scrollLeft(pos.left)
        }
    }
    getContent(isFixedTableRendering) {
        var _this$_tableElement2;
        return null === (_this$_tableElement2 = this._tableElement) || void 0 === _this$_tableElement2 ? void 0 : _this$_tableElement2.parent()
    }
    _removeContent(isFixedTableRendering) {
        const $scrollContainer = this.getContent(isFixedTableRendering);
        if (null !== $scrollContainer && void 0 !== $scrollContainer && $scrollContainer.length) {
            $scrollContainer.remove()
        }
    }
    handleScroll(e) {
        const scrollLeft = (0, _renderer.default)(e.target).scrollLeft();
        if (scrollLeft !== this._scrollLeft) {
            this.scrollChanged.fire({
                left: scrollLeft
            }, this.name)
        }
    }
    _wrapTableInScrollContainer($table, isFixedTableRendering) {
        const $scrollContainer = (0, _renderer.default)("<div>");
        const useNative = this.option("scrolling.useNative");
        if (false === useNative || "auto" === useNative && !_m_support.default.nativeScrolling) {
            $scrollContainer.addClass(this.addWidgetPrefix(_const7.CLASSES.scrollableSimulated))
        }
        _events_engine.default.on($scrollContainer, "scroll", this.handleScroll.bind(this));
        $scrollContainer.addClass(this.addWidgetPrefix(_const7.CLASSES.content)).addClass(this.addWidgetPrefix(_const7.CLASSES.scrollContainer)).append($table).appendTo(this.element());
        this.setAria("role", "presentation", $scrollContainer);
        return $scrollContainer
    }
    needWaitAsyncTemplates() {
        return this.option("templatesRenderAsynchronously") && false === this.option("renderAsync")
    }
    isWaitingForAsyncTemplates() {
        var _this$_templateDeferr;
        return !!this.needWaitAsyncTemplates() && (null === (_this$_templateDeferr = this._templateDeferreds) || void 0 === _this$_templateDeferr ? void 0 : _this$_templateDeferr.size) > 0
    }
    waitAsyncTemplates() {
        let forceWaiting = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : false;
        const result = (0, _deferred.Deferred)();
        const needWaitAsyncTemplates = forceWaiting || this.needWaitAsyncTemplates();
        if (!needWaitAsyncTemplates || !(0, _type.isDefined)(this._templateDeferreds)) {
            return result.resolve()
        }
        const waitTemplatesRecursion = () => _deferred.when.apply(this, Array.from(this._templateDeferreds)).done(() => {
            if (this.isDisposed()) {
                result.reject()
            } else if (this._templateDeferreds.size > 0) {
                waitTemplatesRecursion()
            } else {
                result.resolve()
            }
        }).fail(result.reject);
        waitTemplatesRecursion();
        return result.promise()
    }
    _updateContent($newTableElement, change, isFixedTableRendering) {
        return this.waitAsyncTemplates().done(() => {
            this._removeContent(isFixedTableRendering);
            this.setTableElement($newTableElement, isFixedTableRendering);
            this._wrapTableInScrollContainer($newTableElement, isFixedTableRendering)
        })
    }
    _findContentElement(isFixedTableRendering) {
        return
    }
    _getWidths($cellElements) {
        if (!$cellElements) {
            return []
        }
        const result = [];
        const cellElements = $cellElements.toArray();
        cellElements.forEach(cell => {
            let width = cell.offsetWidth;
            if (cell.getBoundingClientRect) {
                const rect = (0, _position.getBoundingRect)(cell);
                if (rect.width > cell.offsetWidth - 1) {
                    width = rect.width
                }
            }
            result.push(width)
        });
        return result
    }
    getColumnWidths($tableElement, rowIndex) {
        (this.option("forceApplyBindings") ?? _common.noop)();
        const $table = $tableElement ?? this.getTableElement();
        if ($table) {
            const $rows = $table.children(`tbody:not(.${_const7.CLASSES.headerBody})`).children();
            for (let i = 0; i < $rows.length; i += 1) {
                const $row = $rows.eq(i);
                const isGroupRow = $row.hasClass(_const7.CLASSES.groupRow);
                const isDetailRow = $row.hasClass(_const6.CLASSES.detailRow);
                const isErrorRow = $row.hasClass(_const4.CLASSES.errorRow);
                const isRowVisible = (0, _utils.isRowElementVisible)($row.get(0));
                const isRelevantRow = !isGroupRow && !isDetailRow && !isErrorRow;
                if (isRowVisible && isRelevantRow) {
                    const $cells = $row.children("td");
                    return this._getWidths($cells)
                }
            }
        }
        return []
    }
    getVisibleColumnIndex(columnIndex, rowIndex) {
        return columnIndex
    }
    setCellPropertiesCore(styleProps, $row, visibleCellIndex) {
        const $cell = $row.hasClass(_const7.CLASSES.groupRow) ? $row.find(`td[aria-colindex='${visibleCellIndex+1}']:not(.${_const7.CLASSES.groupCell})`) : $row.find("td").eq(visibleCellIndex);
        for (let i = 0; i < $cell.length; i += 1) {
            const cell = $cell.get(i);
            Object.assign(cell.style, styleProps)
        }
    }
    setCellProperties(styleProps, columnIndex, rowIndex) {
        const $tableElement = this.getTableElement();
        if (!(null !== $tableElement && void 0 !== $tableElement && $tableElement.length)) {
            return
        }
        const $rows = $tableElement.children().children(`.${_const7.CLASSES.row}`).not(`.${_const6.CLASSES.detailRow}`);
        if ((0, _type.isDefined)(rowIndex)) {
            this.setCellPropertiesCore(styleProps, $rows.eq(rowIndex), columnIndex)
        } else {
            for (let currentRowIndex = 0; currentRowIndex < $rows.length; currentRowIndex += 1) {
                const visibleIndex = this.getVisibleColumnIndex(columnIndex, currentRowIndex);
                if (visibleIndex >= 0) {
                    this.setCellPropertiesCore(styleProps, $rows.eq(currentRowIndex), visibleIndex)
                }
            }
        }
    }
    setColumnWidths(_ref3) {
        let {
            widths: widths,
            optionNames: optionNames
        } = _ref3;
        const $tableElement = this.getTableElement();
        if (!(null !== $tableElement && void 0 !== $tableElement && $tableElement.length) || !widths) {
            return
        }
        const columns = this.getColumns();
        const needToSetCellWidths = this._needToSetCellWidths();
        const $cols = $tableElement.children("colgroup").children("col");
        $cols.toArray().forEach(col => col.removeAttribute("style"));
        columns.forEach((column, columnIndex) => {
            if (needToSetCellWidths && column.width && !column.command) {
                const styleProps = {};
                const width = getWidthStyle(column.visibleWidth || column.width);
                const minWidth = getWidthStyle(column.minWidth || width);
                styleProps.width = "auto" === column.width ? "" : width;
                styleProps.maxWidth = styleProps.width;
                styleProps.minWidth = minWidth;
                this.setCellProperties(styleProps, columnIndex)
            }
            const colWidth = normalizeWidth(widths[columnIndex]);
            if ((0, _type.isDefined)(colWidth)) {
                (0, _style.setWidth)($cols.eq(columnIndex), colWidth)
            }
        })
    }
    getCellElements(rowIndex) {
        return this._getCellElementsCore(rowIndex)
    }
    _getCellElementsCore(rowIndex) {
        if (rowIndex < 0) {
            return
        }
        const $row = this._getRowElements().eq(rowIndex);
        return $row.children()
    }
    _getCellElement(rowIndex, columnIdentifier) {
        const $cells = this.getCellElements(rowIndex) ?? (0, _renderer.default)();
        const columnVisibleIndex = this._getVisibleColumnIndex($cells, rowIndex, columnIdentifier);
        if (!(null !== $cells && void 0 !== $cells && $cells.length) || columnVisibleIndex < 0) {
            return
        }
        const $cell = $cells.eq(columnVisibleIndex);
        return $cell.length > 0 ? $cell : void 0
    }
    _getRowElement(rowIndex) {
        let $rowElement = (0, _renderer.default)();
        const $tableElements = this.getTableElements();
        $tableElements.toArray().forEach(tableElement => {
            $rowElement = $rowElement.add(this._getRowElements((0, _renderer.default)(tableElement)).eq(rowIndex))
        });
        if ($rowElement.length) {
            return $rowElement
        }
        return
    }
    getCellElement(rowIndex, columnIdentifier) {
        const $cell = this._getCellElement(rowIndex, columnIdentifier);
        if ($cell) {
            return (0, _element.getPublicElement)($cell)
        }
        return
    }
    getRowElement(rowIndex) {
        const $rows = this._getRowElement(rowIndex);
        let elements = [];
        if ($rows && !(0, _element.getPublicElement)($rows).get) {
            for (const row of $rows.toArray()) {
                elements.push(row)
            }
        } else {
            elements = $rows
        }
        return elements
    }
    _getVisibleColumnIndex($cells, rowIndex, columnIdentifier) {
        if ((0, _type.isString)(columnIdentifier)) {
            const columnIndex = this._columnsController.columnOption(columnIdentifier, "index");
            return this._columnsController.getVisibleIndex(columnIndex)
        }
        return columnIdentifier
    }
    getColumnElements() {
        return
    }
    getColumns(rowIndex, $tableElement) {
        return this._columnsController.getVisibleColumns(rowIndex)
    }
    getCell(cellPosition, rows, cells) {
        const $rows = rows ?? this._getRowElements();
        if ($rows.length > 0 && cellPosition.rowIndex >= 0) {
            if ("virtual" !== this.option("scrolling.mode") && "virtual" !== this.option("scrolling.rowRenderingMode")) {
                cellPosition.rowIndex = cellPosition.rowIndex < $rows.length ? cellPosition.rowIndex : $rows.length - 1
            }
            const $cells = cells ?? this.getCellElements(cellPosition.rowIndex);
            if ($cells && $cells.length > 0) {
                return $cells.eq($cells.length > cellPosition.columnIndex ? cellPosition.columnIndex : $cells.length - 1)
            }
        }
        return
    }
    getRowsCount() {
        const tableElement = this.getTableElement();
        if (1 === (null === tableElement || void 0 === tableElement ? void 0 : tableElement.length)) {
            const table = tableElement[0];
            return table.rows.length
        }
        return 0
    }
    _getRowElementsCore(tableElement) {
        const $table = tableElement ?? this.getTableElement();
        if ($table) {
            const hasRowTemplate = this.option().rowTemplate || this.option("dataRowTemplate");
            const tBodies = hasRowTemplate && $table.find(`> tbody.${_const7.CLASSES.row}`);
            return tBodies && tBodies.length ? tBodies : $table.find(`> tbody > .${_const7.CLASSES.row}, > .${_const7.CLASSES.row}`)
        }
        return (0, _renderer.default)()
    }
    _getRowElements(tableElement) {
        return this._getRowElementsCore(tableElement)
    }
    getRowIndex($row) {
        return this._getRowElements().index($row)
    }
    getBoundingRect() {
        return
    }
    getName() {
        return
    }
    setScrollerSpacing(width) {
        const $element = this.element();
        null === $element || void 0 === $element || $element.toggleClass(this.addWidgetPrefix(_const7.CLASSES.scrollerSpacing), !!width).css("paddingInlineEnd", width ? `${width}px` : "")
    }
    isScrollbarVisible(isHorizontal) {
        const $element = this.element();
        const $tableElement = this._tableElement;
        if ($element && $tableElement) {
            return isHorizontal ? (0, _size.getOuterWidth)($tableElement) - (0, _size.getWidth)($element) > 0 : (0, _size.getOuterHeight)($tableElement) - (0, _size.getHeight)($element) > 0
        }
        return false
    }
    isDisposed() {
        var _this$component;
        return null === (_this$component = this.component) || void 0 === _this$component ? void 0 : _this$component._disposed
    }
    renderDragCellContent($dragContainer, column) {
        $dragContainer.text(column.caption ?? "")
    }
    updateFirstCellClasses() {
        const rows = this._getRows();
        this.removeFirstCellClasses();
        rows.forEach((row, index) => {
            const rowIndex = "header" === row.rowType ? index : null;
            const firstColumn = this._columnsController.getFirstColumn(rowIndex);
            if (firstColumn) {
                const $cell = this._getCellElement(index, `index:${firstColumn.index}`);
                this.toggleFirstCellClass($cell, true)
            }
        })
    }
}
exports.ColumnsView = ColumnsView;