UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

1,197 lines (1,195 loc) • 49.6 kB
/** * DevExtreme (esm/__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/ */ import { name as clickEventName } from "../../../../common/core/events/click"; import eventsEngine from "../../../../common/core/events/core/events_engine"; import { name as dblclickEvent } from "../../../../common/core/events/double_click"; import pointerEvents from "../../../../common/core/events/pointer"; import { removeEvent } from "../../../../common/core/events/remove"; import domAdapter from "../../../../core/dom_adapter"; import { getPublicElement } from "../../../../core/element"; import { data as elementData } from "../../../../core/element_data"; import Guid from "../../../../core/guid"; import $ from "../../../../core/renderer"; import browser from "../../../../core/utils/browser"; import { noop } from "../../../../core/utils/common"; import { Deferred, when } from "../../../../core/utils/deferred"; import { extend } from "../../../../core/utils/extend"; import { getBoundingRect, getDefaultAlignment } from "../../../../core/utils/position"; import { getHeight, getOuterHeight, getOuterWidth, getWidth } from "../../../../core/utils/size"; import { setWidth } from "../../../../core/utils/style"; import { isDefined, isFunction, isNumeric, isRenderer, isString } from "../../../../core/utils/type"; import { getWindow, hasWindow } from "../../../../core/utils/window"; import supportUtils from "../../../core/utils/m_support"; import { CLASSES as COLUMN_FIXING_CLASSES } from "../../../grids/grid_core/column_fixing/const"; import { CLASSES as COLUMN_HEADERS_CLASSES } from "../../../grids/grid_core/column_headers/const"; import { ColumnStateMixin } from "../../../grids/grid_core/column_state_mixin/column_state_mixin"; import { CLASSES as COLUMNS_CONTROLLER_CLASSES } from "../../../grids/grid_core/columns_controller/const"; import { CLASSES as ERROR_HANDLING_CLASSES } from "../../../grids/grid_core/error_handling/const"; import { CLASSES as FILTER_ROW_CLASSES } from "../../../grids/grid_core/filter_row/const"; import gridCoreUtils from "../../../grids/grid_core/m_utils"; import { CLASSES as MASTER_DETAIL_CLASSES } from "../../../grids/grid_core/master_detail/const"; import modules from "../../../grids/grid_core/modules/modules"; import { FIELD_ITEM_CONTENT_CLASS } from "../../../ui/form/constants"; import { CLASSES } from "./const"; import { isRowElementVisible } from "./utils"; 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 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 && !isRenderer(template); export const normalizeWidth = width => { if ("number" === typeof width) { return `${width.toFixed(3)}px` } if ("adaptiveHidden" === width) { return "0.0001px" } return width }; export class ColumnsView extends(ColumnStateMixin(modules.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 (hasWindow()) { var _this$_templateTimeou, _this$_templateTimeou2; const 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 = 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 ?? getDefaultAlignment(this.option("rtlEnabled")); const needToSetCellWidths = this._needToSetCellWidths(); const cell = domAdapter.createElement("td"); cell.style.textAlign = alignment; const $cell = $(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 (isDefined(column.cssClass)) { $cell.addClass(column.cssClass) } $cell.addClass(this.addWidgetPrefix(CLASSES.groupSpace)) } if (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 = $(`<${tagName}>`).addClass(CLASSES.row); if ("tr" === tagName) { this.setAria("role", "row", $element) } return $element } _isAltRow(row) { return row && isDefined(row.dataIndex) && row.dataIndex % 2 === 1 } _createTable(columns, isAppend) { const $table = $("<table>").addClass(this.addWidgetPrefix(CLASSES.table)).addClass(this.addWidgetPrefix(CLASSES.tableFixed)); if (columns && !isAppend) { $table.attr("id", `dx-${new Guid}`).append(this._createColGroup(columns)); if (browser.safari) { $table.append($("<thead>").append("<tr>")) } this.setAria("role", "presentation", $table) } else { this.setAria("hidden", true, $table) } this.setAria("role", "presentation", $("<tbody>").appendTo($table)); if (isAppend) { return $table } if (browser.mozilla) { eventsEngine.on($table, "mousedown", "td", e => { if (e.ctrlKey) { e.preventDefault() } }) } if (this.option("cellHintEnabled")) { eventsEngine.on($table, "mousemove", `.${CLASSES.row} > td`, this.createAction(args => { var _rowOptions$cells; const e = args.event; const $element = $(e.target); const $cell = $(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(COLUMN_HEADERS_CLASSES.headerRow); const isDataRow = $row.hasClass(CLASSES.dataRow); const isMasterDetailRow = $row.hasClass(MASTER_DETAIL_CLASSES.detailRow); const isGroupRow = $row.hasClass(CLASSES.groupRow); const isFilterRow = $row.hasClass(this.addWidgetPrefix(FILTER_ROW_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 = $(event.currentTarget); const $fieldItemContent = $(event.target).closest(`.${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 = extend({}, options, { cellElement: 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 }; eventsEngine.on($table, "mouseover", `.${CLASSES.row} > td`, e => { const options = getOptions(e); if (options) { this.executeAction("onCellHoverChanged", options) } }); eventsEngine.on($table, "mouseout", `.${CLASSES.row} > td`, e => { const options = getOptions(e); if (options) { this.executeAction("onCellHoverChanged", options) } }); eventsEngine.on($table, clickEventName, `.${CLASSES.row} > td`, e => { const options = getOptions(e); if (options) { this.executeAction("onCellClick", options) } }); eventsEngine.on($table, dblclickEvent, `.${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) } eventsEngine.on($table, "touchstart touchend", `.${CLASSES.row}`, e => { clearTimeout(timeoutId); if ("touchstart" === e.type) { touchTargets = { target: e.target, currentTarget: e.currentTarget }; timeoutId = clearTouchTargets(1e3) } else { timeoutId = clearTouchTargets() } }); eventsEngine.on($table, [clickEventName, dblclickEvent, pointerEvents.down].join(" "), `.${CLASSES.row}`, this.createAction(e => { const { event: event } = e; if (!gridCoreUtils.isElementInCurrentGrid(this, $(event.target))) { return } if (touchTargets) { event.target = touchTargets.target; event.currentTarget = touchTargets.currentTarget } if (!$(event.target).closest("a").length) { e.rowIndex = this.getRowIndex(event.currentTarget); if (e.rowIndex >= 0) { e.rowElement = getPublicElement($(event.currentTarget)); e.columns = this.getColumns(); if (event.type === pointerEvents.down) { this._rowPointerDown(e) } else if (event.type === clickEventName) { 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(COLUMN_HEADERS_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 || 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 = $("<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 = $("<col>"); 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 = 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 = domAdapter.getRootNode($(options.container).get(0)); const needWaitAsyncTemplates = this.needWaitAsyncTemplates(); if (!isAsync || $(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 (isFunction(template)) { return { render(templateOptions) { var _templateOptions$defe2; const renderedTemplate = template(getPublicElement(templateOptions.container), templateOptions.model, templateOptions.change); if (renderedTemplate && (renderedTemplate.nodeType || isRenderer(renderedTemplate))) { templateOptions.container.append(renderedTemplate) } null === (_templateOptions$defe2 = templateOptions.deferred) || void 0 === _templateOptions$defe2 || _templateOptions$defe2.resolve() } } } const templateID = isString(template) ? template : $(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 = 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); eventsEngine.on(container, removeEvent, () => { templateDeferred.resolve() }) } else { templateDeferred.reject() } return templateDeferred.promise().always(() => { this._templateDeferreds.delete(templateDeferred) }) } _getBodies(tableElement) { return $(tableElement).children("tbody").not(`.${CLASSES.headerBody}`).not(`.${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(`.${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 = $("<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(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(CLASSES.firstCell), isFirstValue) } _resizeCore() { this.updateScrollLeftPosition() } _renderCore(e) { const $root = this.element().parent(); if (!$root || $root.parent().length) { this.renderDelayedTemplates(e) } return 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, 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 = 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, 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 (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(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, $(cell)) }) } columnIndices.forEach((columnIndex, index) => { const $cell = $cells.eq(columnIndex); const $newCell = $newCells.eq(index); $cell.replaceWith($newCell); if (highlightChanges && !$newCell.hasClass(COLUMNS_CONTROLLER_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); 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 = getPublicElement($(cell)); this.executeAction("onCellPrepared", options) } _rowPrepared($row, options, row) { elementData($row.get(0), "options", options); options.rowElement = getPublicElement($row); this.executeAction("onRowPrepared", options) } _columnOptionChanged(_ref2) { let { optionNames: optionNames } = _ref2; if (gridCoreUtils.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 ?? $() } getTableElement(isFixedTableRendering) { return this._tableElement } setTableElement(tableElement, isFixedTableRendering) { this._tableElement = tableElement } _afterRowPrepared(e) {} _handleDataChanged(e) {} callbackNames() { return ["scrollChanged"] } updateScrollLeftPosition() { const scrollLeft = this._scrollLeft; if (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(CLASSES.scrollContainer)}`).not(`.${this.addWidgetPrefix(COLUMN_FIXING_CLASSES.contentFixed)}`); if (isDefined(pos) && 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 = $(e.target).scrollLeft(); if (scrollLeft !== this._scrollLeft) { this.scrollChanged.fire({ left: scrollLeft }, this.name) } } _wrapTableInScrollContainer($table, isFixedTableRendering) { const $scrollContainer = $("<div>"); const useNative = this.option("scrolling.useNative"); if (false === useNative || "auto" === useNative && !supportUtils.nativeScrolling) { $scrollContainer.addClass(this.addWidgetPrefix(CLASSES.scrollableSimulated)) } eventsEngine.on($scrollContainer, "scroll", this.handleScroll.bind(this)); $scrollContainer.addClass(this.addWidgetPrefix(CLASSES.content)).addClass(this.addWidgetPrefix(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 = Deferred(); const needWaitAsyncTemplates = forceWaiting || this.needWaitAsyncTemplates(); if (!needWaitAsyncTemplates || !isDefined(this._templateDeferreds)) { return result.resolve() } const waitTemplatesRecursion = () => 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 = getBoundingRect(cell); if (rect.width > cell.offsetWidth - 1) { width = rect.width } } result.push(width) }); return result } getColumnWidths($tableElement, rowIndex) { (this.option("forceApplyBindings") ?? noop)(); const $table = $tableElement ?? this.getTableElement(); if ($table) { const $rows = $table.children(`tbody:not(.${CLASSES.headerBody})`).children(); for (let i = 0; i < $rows.length; i += 1) { const $row = $rows.eq(i); const isGroupRow = $row.hasClass(CLASSES.groupRow); const isDetailRow = $row.hasClass(MASTER_DETAIL_CLASSES.detailRow); const isErrorRow = $row.hasClass(ERROR_HANDLING_CLASSES.errorRow); const isRowVisible = 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(CLASSES.groupRow) ? $row.find(`td[aria-colindex='${visibleCellIndex+1}']:not(.${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(`.${CLASSES.row}`).not(`.${MASTER_DETAIL_CLASSES.detailRow}`); if (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 (isDefined(colWidth)) { 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) ?? $(); 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 = $(); const $tableElements = this.getTableElements(); $tableElements.toArray().forEach(tableElement => { $rowElement = $rowElement.add(this._getRowElements($(tableElement)).eq(rowIndex)) }); if ($rowElement.length) { return $rowElement } return } getCellElement(rowIndex, columnIdentifier) { const $cell = this._getCellElement(rowIndex, columnIdentifier); if ($cell) { return getPublicElement($cell) } return } getRowElement(rowIndex) { const $rows = this._getRowElement(rowIndex); let elements = []; if ($rows && !getPublicElement($rows).get) { for (const row of $rows.toArray()) { elements.push(row) } } else { elements = $rows } return elements } _getVisibleColumnIndex($cells, rowIndex, columnIdentifier) { if (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.${CLASSES.row}`); return tBodies && tBodies.length ? tBodies : $table.find(`> tbody > .${CLASSES.row}, > .${CLASSES.row}`) } return $() } _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(CLASSES.scrollerSpacing), !!width).css("paddingInlineEnd", width ? `${width}px` : "") } isScrollbarVisible(isHorizontal) { const $element = this.element(); const $tableElement = this._tableElement; if ($element && $tableElement) { return isHorizontal ? getOuterWidth($tableElement) - getWidth($element) > 0 : getOuterHeight($tableElement) - 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) } }) } }