UNPKG

igniteui-react-grids

Version:

Ignite UI React grid components.

407 lines (402 loc) 12.9 kB
import { __assign, __extends } from "tslib"; import * as React from 'react'; import { IgrTreeGridRecord } from "./igr-tree-grid-record"; import { IgrRowType } from "./igr-row-type"; import { IgrCellType } from "./igr-cell-type"; import { IgrGridBaseDirective } from "./igr-grid-base-directive"; import { TreeGrid } from "./TreeGrid"; import { isValidProp, ensureBool } from "igniteui-react-core"; import { ReactTemplateAdapter } from "igniteui-react-core"; import { html } from "lit-html"; var IgrTreeGrid = /** @class */ /*@__PURE__*/ (function (_super) { __extends(IgrTreeGrid, _super); function IgrTreeGrid(props) { var _this = _super.call(this, props) || this; _this._getMainRef = _this._getMainRef.bind(_this); return _this; } IgrTreeGrid.prototype.createImplementation = function () { var _a, _b; var impl = new TreeGrid(); var nat; if (typeof document !== 'undefined') { nat = document.createElement("igc-tree-grid"); } else { nat = { style: {} }; } if ((_a = this.props) === null || _a === void 0 ? void 0 : _a.className) { nat.className = this.props.className; } if ((_b = this.props) === null || _b === void 0 ? void 0 : _b.id) { nat.id = this.props.id; } impl.setNativeElement(nat); return impl; }; Object.defineProperty(IgrTreeGrid.prototype, "i", { /** * @hidden */ get: function () { return this._implementation; }, enumerable: false, configurable: true }); IgrTreeGrid.prototype.componentDidMount = function () { this.mounted = true; _super.prototype.componentDidMount.call(this); this._elRef.appendChild(this.i.nativeElement); }; IgrTreeGrid.prototype.render = function () { var _this = this; var nativePropsName = Object.keys(this.props).filter(function (prop) { return !isValidProp(_this, prop) && prop !== "originalRef" && prop !== "className"; }); var nativeProps = {}; nativePropsName.forEach(function (propName) { nativeProps[propName] = _this.props[propName]; }); var visibleChildren = []; React.Children.forEach(this.props.children, function (ch) { if (ch) { visibleChildren.push(ch); } }); var children = this._contentChildrenManager.getChildren(visibleChildren); this._portalManager.onRender(children); var style = {}; style.display = 'contents'; if (this.props.style) { style = this.props.style; } var div = React.createElement("div", __assign(__assign({}, nativeProps), { ref: this._getMainRef, style: style, children: children })); return div; }; IgrTreeGrid.prototype._getMainRef = function (ref) { this._elRef = ref; }; Object.defineProperty(IgrTreeGrid.prototype, "childDataKey", { get: function () { return this.i.hf; }, set: function (v) { this.i.hf = v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrTreeGrid.prototype, "foreignKey", { get: function () { return this.i.hg; }, set: function (v) { this.i.hg = v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrTreeGrid.prototype, "hasChildrenKey", { get: function () { return this.i.hh; }, set: function (v) { this.i.hh = v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrTreeGrid.prototype, "cascadeOnDelete", { get: function () { return this.i.g9; }, set: function (v) { this.i.g9 = ensureBool(v); }, enumerable: false, configurable: true }); Object.defineProperty(IgrTreeGrid.prototype, "id", { get: function () { return this.i.hi; }, set: function (v) { this.i.hi = v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrTreeGrid.prototype, "rootRecords", { /** * Returns an array of the root level `ITreeGridRecord`s. * ```typescript * // gets the root record with index=2 * const states = this.grid.rootRecords[2]; * ``` * @memberof IgxTreeGridComponent */ get: function () { if (!this.i.g3) { return undefined; } var ret = []; for (var i = 0; i < this.i.g3.length; i++) { var impl = this.i.g3[i]; if (!impl.externalObject) { if (impl instanceof IgrTreeGridRecord) { ret.push(impl); continue; } var e = new IgrTreeGridRecord(); e._implementation = impl; impl.externalObject = e; } ret.push(impl.externalObject); } return ret; }, set: function (v) { var arr = []; for (var i = 0; i < v.length; i++) { arr.push(v[i].i); } this.i.g3 = arr; }, enumerable: false, configurable: true }); Object.defineProperty(IgrTreeGrid.prototype, "processedRootRecords", { /** * Returns an array of processed (filtered and sorted) root `ITreeGridRecord`s. * ```typescript * // gets the processed root record with index=2 * const states = this.grid.processedRootRecords[2]; * ``` * @memberof IgxTreeGridComponent */ get: function () { if (!this.i.g2) { return undefined; } var ret = []; for (var i = 0; i < this.i.g2.length; i++) { var impl = this.i.g2[i]; if (!impl.externalObject) { if (impl instanceof IgrTreeGridRecord) { ret.push(impl); continue; } var e = new IgrTreeGridRecord(); e._implementation = impl; impl.externalObject = e; } ret.push(impl.externalObject); } return ret; }, set: function (v) { var arr = []; for (var i = 0; i < v.length; i++) { arr.push(v[i].i); } this.i.g2 = arr; }, enumerable: false, configurable: true }); Object.defineProperty(IgrTreeGrid.prototype, "data", { get: function () { return this.i.g0; }, set: function (v) { if (v && !Array.isArray(v) && typeof (v) == "string") { var re = /\s*(?:,|\s|$)\s*/gm; v = v.split(re); } this.i.g0 = v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrTreeGrid.prototype, "expansionDepth", { get: function () { return this.i.hc; }, set: function (v) { this.i.hc = +v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrTreeGrid.prototype, "rowLoadingIndicatorTemplate", { get: function () { return this._rowLoadingIndicatorTemplate; }, set: function (v) { this._rowLoadingIndicatorTemplate = v; if (!this._rowLoadingIndicatorTemplateAdapter) { this._rowLoadingIndicatorTemplateAdapter = new ReactTemplateAdapter(this._renderer, this._portalManager, "he", { html: html }); } this._rowLoadingIndicatorTemplateAdapter.setValue(this.i, this._rowLoadingIndicatorTemplate); }, enumerable: false, configurable: true }); Object.defineProperty(IgrTreeGrid.prototype, "selectedCells", { /** * Returns an array of the selected `IgxGridCell`s. * @example * ```typescript * const selectedCells = this.grid.selectedCells; * ``` */ get: function () { if (!this.i.g4) { return undefined; } var ret = []; for (var i = 0; i < this.i.g4.length; i++) { var impl = this.i.g4[i]; if (!impl.externalObject) { if (impl instanceof IgrCellType) { ret.push(impl); continue; } var e = new IgrCellType(); e._implementation = impl; impl.externalObject = e; } ret.push(impl.externalObject); } return ret; }, enumerable: false, configurable: true }); IgrTreeGrid.prototype.getDefaultExpandState = function (record) { this.i.hn((record == null ? null : record.i)); }; /** * Expands all rows. * ```typescript * this.grid.expandAll(); * ``` * @memberof IgxTreeGridComponent */ IgrTreeGrid.prototype.expandAll = function () { this.i.hm(); }; /** * Collapses all rows. * ```typescript * this.grid.collapseAll(); * ``` * @memberof IgxTreeGridComponent */ IgrTreeGrid.prototype.collapseAll = function () { this.i.hl(); }; IgrTreeGrid.prototype.addRow = function (data, parentRowID) { this.i.hj(data, parentRowID); }; IgrTreeGrid.prototype.beginAddRowByIndex = function (index, asChild) { this.i.hk(index, asChild); }; IgrTreeGrid.prototype.getSelectedData = function (formatters, headers) { var iv = this.i.g1(formatters, headers); return (iv); }; /** * Returns the `IgxTreeGridRow` by index. * @example * ```typescript * const myRow = treeGrid.getRowByIndex(1); * ``` * index * @param * index */ IgrTreeGrid.prototype.getRowByIndex = function (index) { var iv = this.i.g7(index); var ret = null; if (iv && iv.externalObject) { ret = iv.externalObject; } else { if (iv) { var e = new IgrRowType(); e._implementation = iv; iv.externalObject = e; ret = e; } } return ret; }; /** * Returns the `RowType` object by the specified primary key. * @example * ```typescript * const myRow = this.treeGrid.getRowByIndex(1); * ``` * index * @param * index */ IgrTreeGrid.prototype.getRowByKey = function (key) { var iv = this.i.g8(key); var ret = null; if (iv && iv.externalObject) { ret = iv.externalObject; } else { if (iv) { var e = new IgrRowType(); e._implementation = iv; iv.externalObject = e; ret = e; } } return ret; }; IgrTreeGrid.prototype.getCellByColumn = function (rowIndex, columnField) { var iv = this.i.g5(rowIndex, columnField); var ret = null; if (iv && iv.externalObject) { ret = iv.externalObject; } else { if (iv) { var e = new IgrCellType(); e._implementation = iv; iv.externalObject = e; ret = e; } } return ret; }; IgrTreeGrid.prototype.getCellByKey = function (rowSelector, columnField) { var iv = this.i.g6(rowSelector, columnField); var ret = null; if (iv && iv.externalObject) { ret = iv.externalObject; } else { if (iv) { var e = new IgrCellType(); e._implementation = iv; iv.externalObject = e; ret = e; } } return ret; }; IgrTreeGrid.prototype.pinRow = function (rowID, index) { var iv = this.i.ha(rowID, index); return (iv); }; IgrTreeGrid.prototype.unpinRow = function (rowID) { var iv = this.i.hb(rowID); return (iv); }; return IgrTreeGrid; }(IgrGridBaseDirective)); export { IgrTreeGrid };