UNPKG

igniteui-react-grids

Version:

Ignite UI React grid components.

471 lines (466 loc) 14.6 kB
import * as React from 'react'; import { ensureEnum, brushToString, stringToBrush, ensureBool, initializePropertiesFromCss, NamePatcher, isValidProp, toSpinal, getModifiedProps } from "igniteui-react-core"; import { FontInfo } from "igniteui-react-core"; import { ReactRenderer } from "igniteui-react-core"; import { DataGridToolbar } from './DataGridToolbar'; import { IgrDataGrid } from "./igr-data-grid"; import { IgrColumnChooser } from "./igr-column-chooser"; import { IgrColumnPinning } from "./igr-column-pinning"; import { ControlDisplayDensity_$type } from "igniteui-react-core"; import { BaseControlTheme_$type } from "igniteui-react-core"; import { Thickness } from "igniteui-react-core"; export class IgrDataGridToolbar extends React.Component { set height(value) { this._height = value; if (this._elRef) { this._elRef.style.height = value; this._toolbar.notifySizeChanged(); } } get height() { return this._height; } set width(value) { this._width = value; if (this._elRef) { this._elRef.style.height = value; this._toolbar.notifySizeChanged(); } } get width() { return this._width; } _getMainRef(ref) { this._elRef = ref; if (this._elRef != null && this._columnChooserRef != null && this._columnPinningRef != null) { this._renderer = new ReactRenderer(this._elRef, document, false, null); this._toolbar.provideContainer(this._renderer, this._columnChooserRef.i, this._columnPinningRef.i); } } _getColumnChooserRef(ref) { this._columnChooserRef = ref; if (this._elRef != null && this._columnChooserRef != null && this._columnPinningRef != null) { this._renderer = new ReactRenderer(this._elRef, document, false, null); this._toolbar.provideContainer(this._renderer, this._columnChooserRef.i, this._columnPinningRef.i); } } _getColumnPinningRef(ref) { this._columnPinningRef = ref; if (this._elRef != null && this._columnChooserRef != null && this._columnPinningRef != null) { this._renderer = new ReactRenderer(this._elRef, document, false, null); this._toolbar.provideContainer(this._renderer, this._columnChooserRef.i, this._columnPinningRef.i); } } render() { let children = []; let title = React.createElement("span", { key: "titleSpan" }); children.push(title); let buttons = []; let hideBtnContainer = React.createElement("div", { key: "hideBtnContainer" }); buttons.push(hideBtnContainer); let pinBtnContainer = React.createElement("div", { key: "pinBtnContainer" }); buttons.push(pinBtnContainer); /*let exportInput = React.createElement("input", { key: "exportInput", type: "Button" }); buttons.push(exportInput);*/ let buttonsContainer = React.createElement("div", { key: "buttonsContainer", children: buttons }); children.push(buttonsContainer); let chooserDialogChildren = []; let chooserDialog = React.createElement("div", { key: "chooserDialog", children: chooserDialogChildren }); children.push(chooserDialog); let columnChooser = React.createElement(IgrColumnChooser, { ref: this._getColumnChooserRef, key: "columnChooser" }); chooserDialogChildren.push(columnChooser); let pinningChildren = []; let pinningDialog = React.createElement("div", { key: "pinningDialog", children: pinningChildren, }); children.push(pinningDialog); let columnPinning = React.createElement(IgrColumnPinning, { ref: this._getColumnPinningRef, key: "columnPinning" }); pinningChildren.push(columnPinning); /*let exportChildren: any[] = []; let exportDialog = React.createElement("div", { key: "exportDialog", children: exportChildren, style: { background: "white", display: "none", position: "absolute", zIndex: 12000, borderWidth: "1px", borderStyle: "solid" } }); children.push(exportDialog); let exportExcel = React.createElement("input", { key: "exportExcel", type: "Button" }); exportChildren.push(exportExcel); let exportCsv = React.createElement("input", { key: "exportCsv", type: "Button" }); exportChildren.push(exportCsv);*/ let div = React.createElement("div", { className: "ig-data-grid-toolbar igr-data-grid-toolbar", ref: this._getMainRef, children: children }); return div; } constructor(props) { super(props); this._implementation = null; this.__p = null; this._hasUserValues = new Set(); this._stylingContainer = null; this._stylingParent = null; this._inStyling = false; if (this._styling) { NamePatcher.ensureStylablePatched(Object.getPrototypeOf(this)); } this._getMainRef = this._getMainRef.bind(this); this._getColumnChooserRef = this._getColumnChooserRef.bind(this); this._getColumnPinningRef = this._getColumnPinningRef.bind(this); this._implementation = this.createImplementation(); var toolbar = this.i; this._toolbar = toolbar; toolbar.notifySizeChanged(); if (props) { this.initializeProperties(); } } shouldComponentUpdate(nextProps, nextState) { const mod = getModifiedProps(this.props, nextProps); for (const p of Object.keys(mod)) { if (isValidProp(this, p)) { this[p] = mod[p]; } } return true; } initializeProperties() { for (const p of Object.keys(this.props)) { if (isValidProp(this, p)) { this[p] = this.props[p]; } } } // supports angular themes or custom properties set in CSS updateStyle() { this._styling(this._elRef, this); } destroy() { this._toolbar.destroy(); if (this._renderer) { this._renderer.destroy(); } } componentWillUnmount() { } componentDidMount() { this._elRef.style.width = this._width ? this._width : ""; this._elRef.style.height = this._height ? this._height : ""; this._toolbar.notifySizeChanged(); this.initializeContent(); } initializeContent() { this.updateStyle(); this.i.notifySizeChanged(); } createImplementation() { return new DataGridToolbar(); } get i() { return this._implementation; } /** * Gets or Sets the property name that contains the values. */ get targetGrid() { const r = this.i.e; if (r == null) { return null; } if (!r.externalObject) { let e = new IgrDataGrid({}); if (r.$type) { e._implementation = r; } else { if (e.i.setNativeElement) { e.i.setNativeElement(r); } } r.externalObject = e; } return r.externalObject; } set targetGrid(v) { if (v != null && this._stylingContainer && v._styling) v._styling(this._stylingContainer, this, this); v == null ? this.i.e = null : this.i.e = v.i; } /** * Gets or Sets the property name that contains the values. */ get toolbarTitle() { return this.i.ar; } set toolbarTitle(v) { this.i.ar = v; } /** * Gets or Sets the property name that contains the values. */ get toolbarTitleStyle() { if (this.i.n == null) { return null; } return this.i.n.fontString; } set toolbarTitleStyle(v) { let fi = new FontInfo(); fi.fontString = v; this.i.n = fi; } /** * Gets or Sets the property name that contains the values. */ get toolbarTitleColor() { return brushToString(this.i.bg); } set toolbarTitleColor(v) { this.i.bg = stringToBrush(v); } /** * Gets or Sets the property name that contains the values. */ get backgroundColor() { return brushToString(this.i.be); } set backgroundColor(v) { this.i.be = stringToBrush(v); } /** * Gets or Sets the property name that contains the values. */ get dialogBackgroundColor() { return brushToString(this.i.bf); } set dialogBackgroundColor(v) { this.i.bf = stringToBrush(v); } /** * Gets or Sets the property name that contains the values. */ get columnChooser() { return this.i.q; } set columnChooser(v) { this.i.q = ensureBool(v); } /** * Gets or Sets the property name that contains the values. */ get columnChooserText() { return this.i.ad; } set columnChooserText(v) { this.i.ad = v; } /** * Gets or Sets the property name that contains the values. */ get columnChooserTitle() { return this.i.af; } set columnChooserTitle(v) { this.i.af = v; } /** * Gets or Sets the property name that contains the values. */ get columnPinning() { return this.i.r; } set columnPinning(v) { this.i.r = ensureBool(v); } /** * Gets or Sets the property name that contains the values. */ get columnPinningText() { return this.i.ai; } set columnPinningText(v) { this.i.ai = v; } /** * Gets or Sets the property name that contains the values. */ get columnPinningTitle() { return this.i.ak; } set columnPinningTitle(v) { this.i.ak = v; } get borderWidthBottom() { return this.i.bi ? this.i.bi.bottom : NaN; } set borderWidthBottom(v) { this.ensureBorderWidth(); this.i.bi.bottom = +v; this.i.bi = this.i.bi; } get borderWidthLeft() { return this.i.bi ? this.i.bi.left : NaN; } set borderWidthLeft(v) { this.ensureBorderWidth(); this.i.bi.left = +v; this.i.bi = this.i.bi; } get borderWidthRight() { return this.i.bi ? this.i.bi.right : NaN; } set borderWidthRight(v) { this.ensureBorderWidth(); this.i.bi.right = +v; this.i.bi = this.i.bi; } get borderWidthTop() { return this.i.bi ? this.i.bi.top : NaN; } set borderWidthTop(v) { this.ensureBorderWidth(); this.i.bi.top = +v; this.i.bi = this.i.bi; } ensureBorderWidth() { if (this.i.bi) { return; } this.i.bi = new Thickness(2); } /** * Gets or Sets the property name that contains the values. */ get density() { return this.i.l; } set density(v) { this.i.l = ensureEnum(ControlDisplayDensity_$type, v); } /** * Gets or Sets the property name that contains the values. */ get baseTheme() { return this.i.j; } set baseTheme(v) { this.i.j = ensureEnum(BaseControlTheme_$type, v); } findByName(name) { if (this.findEphemera) { if (name && name.indexOf("@@e:") == 0) { return this.findEphemera(name); } } if (this.targetGrid && this.targetGrid.name && this.targetGrid.name == name) { return this.targetGrid; } return null; } get hasUserValues() { return this._hasUserValues; } __m(propertyName) { if (!this._inStyling) { this._hasUserValues.add(propertyName); } } _styling(container, component, parent) { if (this._inStyling) { return; } this._inStyling = true; this._stylingContainer = container; this._stylingParent = component; let genericPrefix = ""; let typeName = this.i.$type.name; if (typeName.indexOf("Xam") === 0) { typeName = typeName.substring(3); } genericPrefix = toSpinal("DataGridToolbar"); let additionalPrefixes = []; let prefix = toSpinal(typeName); additionalPrefixes.push(prefix + "-"); let b = this.i.$type.baseType; while (b && b.name != "Object" && b.name != "Base" && b.name != "Control" && b.Name != "DependencyObject" && b.Name != "FrameworkElement") { typeName = b.name; if (typeName.indexOf("Xam") === 0) { typeName = typeName.substring(3); } let basePrefix = toSpinal(typeName); additionalPrefixes.push(basePrefix + "-"); b = b.baseType; } if (parent) { let parentTypeName = parent.i.$type.name; if (parentTypeName.indexOf("Xam") === 0) { parentTypeName = parentTypeName.substring(3); } let parentPrefix = toSpinal(parentTypeName); additionalPrefixes.push(parentPrefix + "-" + genericPrefix + "-"); additionalPrefixes.push(parentPrefix + "-" + prefix + "-"); } initializePropertiesFromCss(container, this, genericPrefix + "-", this.hasUserValues, false, additionalPrefixes); if (this.targetGrid && this.targetGrid._styling) { this.targetGrid._styling(container, component, this); } if (this._otherStyling) { this._otherStyling(container, component, parent); } this._inStyling = false; } /** * Exports visual information about the current state of the toolbar. */ exportVisualModel() { let iv = this.i.exportVisualModel(); return (iv); } /** * Returns a serialized copy of the exported visual model */ exportSerializedVisualModel() { let iv = this.i.exportSerializedVisualModel(); return (iv); } }