devextreme
Version:
HTML5 JavaScript Component Suite for Responsive Web Development
290 lines (287 loc) • 10.9 kB
JavaScript
/**
* DevExtreme (cjs/__internal/grids/pivot_grid/headers_area/m_headers_area.js)
* Version: 24.2.6
* Build date: Mon Mar 17 2025
*
* Copyright (c) 2012 - 2025 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.default = exports.VerticalHeadersArea = exports.HorizontalHeadersArea = void 0;
var _dom_adapter = _interopRequireDefault(require("../../../../core/dom_adapter"));
var _renderer = _interopRequireDefault(require("../../../../core/renderer"));
var _iterator = require("../../../../core/utils/iterator");
var _size = require("../../../../core/utils/size");
var _type = require("../../../../core/utils/type");
var _ui = _interopRequireDefault(require("../../../../ui/scroll_view/ui.scrollable"));
var _m_area_item = require("../area_item/m_area_item");
function _interopRequireDefault(e) {
return e && e.__esModule ? e : {
default: e
}
}
const PIVOTGRID_AREA_CLASS = "dx-pivotgrid-area";
const PIVOTGRID_AREA_COLUMN_CLASS = "dx-pivotgrid-horizontal-headers";
const PIVOTGRID_AREA_ROW_CLASS = "dx-pivotgrid-vertical-headers";
const PIVOTGRID_TOTAL_CLASS = "dx-total";
const PIVOTGRID_GRAND_TOTAL_CLASS = "dx-grandtotal";
const PIVOTGRID_ROW_TOTAL_CLASS = "dx-row-total";
const PIVOTGRID_EXPANDED_CLASS = "dx-pivotgrid-expanded";
const PIVOTGRID_COLLAPSED_CLASS = "dx-pivotgrid-collapsed";
const PIVOTGRID_LAST_CELL_CLASS = "dx-last-cell";
const PIVOTGRID_VERTICAL_SCROLL_CLASS = "dx-vertical-scroll";
const PIVOTGRID_EXPAND_BORDER = "dx-expand-border";
const isRenovatedScrollable = !!_ui.default.IS_RENOVATED_WIDGET;
function getCellPath(tableElement, cell) {
if (cell) {
const {
data: data
} = tableElement.data();
const {
rowIndex: rowIndex
} = cell.parentNode;
const {
cellIndex: cellIndex
} = cell;
return data[rowIndex] && data[rowIndex][cellIndex] && data[rowIndex][cellIndex].path
}
return
}
const HorizontalHeadersArea = exports.HorizontalHeadersArea = _m_area_item.AreaItem.inherit({
ctor(component) {
this.callBase(component);
this._scrollBarWidth = 0
},
_getAreaName: () => "column",
_getAreaClassName: () => PIVOTGRID_AREA_COLUMN_CLASS,
_createGroupElement() {
return (0, _renderer.default)("<div>").addClass(this._getAreaClassName()).addClass("dx-pivotgrid-area")
},
_applyCustomStyles(options) {
const {
cssArray: cssArray
} = options;
const {
cell: cell
} = options;
const {
rowsCount: rowsCount
} = options;
const {
classArray: classArray
} = options;
if (options.cellIndex === options.cellsCount - 1) {
cssArray.push((options.rtlEnabled ? "border-left:" : "border-right:") + "0px")
}
if (cell.rowspan === rowsCount - options.rowIndex || options.rowIndex + 1 === rowsCount) {
cssArray.push("border-bottom-width:0px")
}
if ("T" === cell.type || "GT" === cell.type) {
classArray.push("dx-row-total")
}
if ("T" === options.cell.type) {
classArray.push("dx-total")
}
if ("GT" === options.cell.type) {
classArray.push("dx-grandtotal")
}
if ((0, _type.isDefined)(cell.expanded)) {
classArray.push(cell.expanded ? "dx-pivotgrid-expanded" : "dx-pivotgrid-collapsed")
}
this.callBase(options)
},
_getMainElementMarkup() {
const thead = _dom_adapter.default.createElement("thead");
thead.setAttribute("class", this._getAreaClassName());
return thead
},
_getCloseMainElementMarkup: () => "</thead>",
setVirtualContentParams(params) {
this.callBase(params);
this._setTableCss({
left: params.left,
top: 0
});
this._virtualContentWidth = params.width
},
hasScroll() {
const tableWidth = this._virtualContent ? this._virtualContentWidth : this._tableWidth;
const groupWidth = this.getGroupWidth();
if (groupWidth && tableWidth) {
return tableWidth - groupWidth >= 1
}
return false
},
renderScrollable() {
this._groupElement.dxScrollable({
useNative: false,
useSimulatedScrollbar: false,
showScrollbar: "never",
bounceEnabled: false,
direction: "horizontal",
rtlEnabled: isRenovatedScrollable ? this.component.option("rtlEnabled") : false,
updateManually: true
})
},
updateScrollableOptions(_ref) {
let {
rtlEnabled: rtlEnabled
} = _ref;
const scrollable = this._getScrollable();
isRenovatedScrollable && scrollable.option({
rtlEnabled: rtlEnabled
})
},
processScrollBarSpacing(scrollBarWidth) {
const groupAlignment = this.option("rtlEnabled") ? "right" : "left";
const groupWidth = this.getGroupWidth();
if (groupWidth) {
this.setGroupWidth(groupWidth - scrollBarWidth)
}
if (this._scrollBarWidth) {
this._groupElement.next().remove()
}
this._groupElement.toggleClass("dx-vertical-scroll", scrollBarWidth > 0);
(0, _size.setWidth)(this._groupElement.css("float", groupAlignment), this.getGroupHeight());
this._scrollBarWidth = scrollBarWidth
},
getScrollPath(offset) {
const tableElement = this.tableElement();
let cell;
offset -= parseInt(tableElement[0].style.left, 10) || 0;
(0, _iterator.each)(tableElement.find("td"), ((_, td) => {
if (1 === td.colSpan && td.offsetLeft <= offset && td.offsetWidth + td.offsetLeft > offset) {
cell = td;
return false
}
return
}));
return getCellPath(tableElement, cell)
},
_moveFakeTable(scrollPos) {
this._moveFakeTableHorizontally(scrollPos);
this.callBase()
}
});
const VerticalHeadersArea = exports.VerticalHeadersArea = HorizontalHeadersArea.inherit({
_getAreaClassName: () => PIVOTGRID_AREA_ROW_CLASS,
_applyCustomStyles(options) {
this.callBase(options);
if (options.cellIndex === options.cellsCount - 1) {
options.classArray.push("dx-last-cell")
}
if (options.rowIndex === options.rowsCount - 1) {
options.cssArray.push("border-bottom: 0px")
}
if (options.cell.isWhiteSpace) {
options.classArray.push("dx-white-space-column")
}
},
_getAreaName: () => "row",
setVirtualContentParams(params) {
this.callBase(params);
this._setTableCss({
top: params.top,
left: 0
});
this._virtualContentHeight = params.height
},
hasScroll() {
const tableHeight = this._virtualContent ? this._virtualContentHeight : this._tableHeight;
const groupHeight = this.getGroupHeight();
if (groupHeight && tableHeight) {
return tableHeight - groupHeight >= 1
}
return false
},
renderScrollable() {
this._groupElement.dxScrollable({
useNative: false,
useSimulatedScrollbar: false,
showScrollbar: "never",
bounceEnabled: false,
direction: "vertical",
updateManually: true
})
},
processScrollBarSpacing(scrollBarWidth) {
const groupHeight = this.getGroupHeight();
if (groupHeight) {
this.setGroupHeight(groupHeight - scrollBarWidth)
}
if (this._scrollBarWidth) {
this._groupElement.next().remove()
}
if (scrollBarWidth) {
const $div = (0, _renderer.default)("<div>");
(0, _size.setWidth)($div, "100%");
(0, _size.setHeight)($div, scrollBarWidth - 1);
this._groupElement.after($div)
}
this._scrollBarWidth = scrollBarWidth
},
getScrollPath(offset) {
const tableElement = this.tableElement();
let cell;
offset -= parseInt(tableElement[0].style.top, 10) || 0;
(0, _iterator.each)(tableElement.find("tr"), ((_, tr) => {
const td = tr.childNodes[tr.childNodes.length - 1];
if (td && 1 === td.rowSpan && td.offsetTop <= offset && td.offsetHeight + td.offsetTop > offset) {
cell = td;
return false
}
return
}));
return getCellPath(tableElement, cell)
},
_moveFakeTable(scrollPos) {
this._moveFakeTableTop(scrollPos);
this.callBase()
},
_getRowClassNames(rowIndex, cell, rowClassNames) {
if (0 !== rowIndex & cell.expanded && !rowClassNames.includes("dx-expand-border")) {
rowClassNames.push("dx-expand-border")
}
},
_getMainElementMarkup() {
const tbody = _dom_adapter.default.createElement("tbody");
tbody.classList.add(this._getAreaClassName());
return tbody
},
_getCloseMainElementMarkup: () => "</tbody>",
updateColspans(columnCount) {
const {
rows: rows
} = this.tableElement()[0];
let columnOffset = 0;
const columnOffsetResetIndexes = [];
if (this.getColumnsCount() - columnCount > 0) {
return
}
for (let i = 0; i < rows.length; i += 1) {
for (let j = 0; j < rows[i].cells.length; j += 1) {
const cell = rows[i].cells[j];
const {
rowSpan: rowSpan
} = cell;
if (columnOffsetResetIndexes[i]) {
columnOffset -= columnOffsetResetIndexes[i];
columnOffsetResetIndexes[i] = 0
}
const diff = columnCount - (columnOffset + cell.colSpan);
if (j === rows[i].cells.length - 1 && diff > 0) {
cell.colSpan += diff
}
columnOffsetResetIndexes[i + rowSpan] = (columnOffsetResetIndexes[i + rowSpan] || 0) + cell.colSpan;
columnOffset += cell.colSpan
}
}
}
});
var _default = exports.default = {
HorizontalHeadersArea: HorizontalHeadersArea,
VerticalHeadersArea: VerticalHeadersArea
};