UNPKG

igniteui-react-grids

Version:

Ignite UI React grid components.

457 lines (453 loc) 14.6 kB
import * as React from 'react'; import { delegateCombine, delegateRemove } from "igniteui-react-core"; import { IgrNumberEventArgs } from "igniteui-react"; import { IgrPageCancellableEventArgs } from "./igr-page-cancellable-event-args"; import { IgrPageEventArgs } from "./igr-page-event-args"; import { Paginator } from "./Paginator"; import { TypeRegistrar } from "igniteui-react-core"; import { ReactRenderer, PortalManager } from "igniteui-react-core"; import { NamePatcher, getModifiedProps, isValidProp, interfaceToInternal, toSpinal, initializePropertiesFromCss } from "igniteui-react-core"; import { OverlaySettings } from "./OverlaySettings"; import { PaginatorResourceStrings } from "./PaginatorResourceStrings"; /** * Paginator component description * @igxParent IgxGridComponent, IgxTreeGridComponent, IgxHierarchicalGridComponent, IgxPivotGridComponent, * */ export class IgrPaginator extends React.Component { createImplementation() { var _a, _b; let impl = new Paginator(); let nat; if (typeof document !== 'undefined') { nat = document.createElement("igc-paginator"); } 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; } get nativeElement() { return this._implementation.nativeElement; } /** * @hidden */ get i() { return this._implementation; } /** * @hidden */ static _createFromInternal(internal) { if (!internal) { return null; } if (!internal.$type) { return null; } let name = internal.$type.name; let externalName = "Igr" + name; if (!TypeRegistrar.isRegistered(externalName)) { return null; } return TypeRegistrar.create(externalName); } onImplementationCreated() { } constructor(props) { super(props); this.mounted = false; this.__p = null; this._hasUserValues = new Set(); this._stylingContainer = null; this._stylingParent = null; this._inStyling = false; this._perPageChange = null; this._perPageChange_wrapped = null; this._pageChange = null; this._pageChange_wrapped = null; this._paging = null; this._paging_wrapped = null; this._pagingDone = null; this._pagingDone_wrapped = null; if (this._styling) { NamePatcher.ensureStylablePatched(Object.getPrototypeOf(this)); } this._getMainRef = this._getMainRef.bind(this); this._implementation = this.createImplementation(); this._portalManager = new PortalManager("templates", () => { if (this.mounted) { this.setState({}); } }); if (typeof window !== 'undefined' && typeof document !== 'undefined') { this._renderer = new ReactRenderer(this._implementation.nativeElement, document, false, null, this._portalManager); } this._implementation.externalObject = this; this.onImplementationCreated(); if (this._initializeAdapters) { this._initializeAdapters(); } } componentDidMount() { this.mounted = true; for (const p of Object.keys(this.props)) { if (isValidProp(this, p)) { this[p] = this.props[p]; } } } 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; } render() { const nativePropsName = Object.keys(this.props).filter(prop => !isValidProp(this, prop) && prop !== "originalRef" && prop !== "className"); const nativeProps = {}; nativePropsName.forEach(propName => { nativeProps[propName] = this.props[propName]; }); let propChildren = this.props.children; let children = []; React.Children.forEach(propChildren, (ch) => { children.push(React.cloneElement(ch)); }); this._portalManager.onRender(children); let style = {}; style.display = 'contents'; if (this.props.style) { style = this.props.style; } let div = React.createElement("div", Object.assign(Object.assign({}, nativeProps), { ref: this._getMainRef, className: this.props.className, style: style, children: children })); return div; } _getMainRef(ref) { this._elRef = ref; } /** * Total pages calculated from totalRecords and perPage */ get totalPages() { return this.i.n; } set totalPages(v) { this.i.n = +v; } /** * Gets/Sets the current page of the paginator. * The default is 0. * ```typescript * let page = this.paginator.page; * ``` * @memberof IgxPaginatorComponent */ get page() { return this.i.l; } set page(v) { this.i.l = +v; } /** * Gets/Sets the number of visible items per page in the paginator. * The default is 15. * ```typescript * let itemsPerPage = this.paginator.perPage; * ``` * @memberof IgxPaginatorComponent */ get perPage() { return this.i.m; } set perPage(v) { this.i.m = +v; } /** * Sets the total records. * ```typescript * let totalRecords = this.paginator.totalRecords; * ``` * @memberof IgxPaginatorComponent */ get totalRecords() { return this.i.o; } set totalRecords(v) { this.i.o = +v; } /** * Sets custom options in the select of the paginator * ```typescript * let options = this.paginator.selectOptions; * ``` * @memberof IgxPaginatorComponent */ get selectOptions() { return this.i.a; } set selectOptions(v) { if (v && !Array.isArray(v) && typeof (v) == "string") { const re = /\s*(?:,|\s|$)\s*/gm; v = v.split(re); } this.i.a = v; } get overlaySettings() { return this.i.d.nativeElement; } set overlaySettings(v) { this.i.d = interfaceToInternal(v, () => new OverlaySettings()); } /** * An accessor that sets the resource strings. * By default it uses EN resources. */ get resourceStrings() { return this.i.g.nativeElement; } set resourceStrings(v) { this.i.g = interfaceToInternal(v, () => new PaginatorResourceStrings()); } /** * Returns if the current page is the last page. * ```typescript * const lastPage = this.paginator.isLastPage; * ``` */ get isLastPage() { return this.i.k; } /** * Returns if the current page is the first page. * ```typescript * const lastPage = this.paginator.isFirstPage; * ``` */ get isFirstPage() { return this.i.j; } get name() { return this.i.r; } set name(v) { this.i.r = v; } findByName(name) { if (this.findEphemera) { if (name && name.indexOf("@@e:") == 0) { return this.findEphemera(name); } } if (this.overlaySettings && this.overlaySettings.name && this.overlaySettings.name == name) { return this.overlaySettings; } if (this.resourceStrings && this.resourceStrings.name && this.resourceStrings.name == name) { return this.resourceStrings; } 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("Paginator"); 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._otherStyling) { this._otherStyling(container, component, parent); } this._inStyling = false; } setNativeElement(element) { this.i.setNativeElement(element); } /** * Goes to the next page of the `IgxPaginatorComponent`, if the paginator is not already at the last page. * ```typescript * this.paginator.nextPage(); * ``` * @memberof IgxPaginatorComponent */ nextPage() { this.i.s(); } /** * Goes to the previous page of the `IgxPaginatorComponent`, if the paginator is not already at the first page. * ```typescript * this.paginator.previousPage(); * ``` * @memberof IgxPaginatorComponent */ previousPage() { this.i.y(); } /** * Goes to the desired page index. * ```typescript * this.paginator.paginate(1); * ``` * val * @memberof IgxPaginatorComponent * @param * val */ paginate(val) { this.i.u(val); } get perPageChange() { return this._perPageChange; } set perPageChange(ev) { if (this._perPageChange_wrapped !== null) { this.i.perPageChange = delegateRemove(this.i.perPageChange, this._perPageChange_wrapped); this._perPageChange_wrapped = null; this._perPageChange = null; } this._perPageChange = ev; this._perPageChange_wrapped = (o, e) => { let outerArgs = new IgrNumberEventArgs(); outerArgs._provideImplementation(e); if (this.beforePerPageChange) { this.beforePerPageChange(this, outerArgs); } if (this._perPageChange) { this._perPageChange(this, outerArgs); } }; this.i.perPageChange = delegateCombine(this.i.perPageChange, this._perPageChange_wrapped); if (this.i.perPageChangeChanged) { this.i.perPageChangeChanged(); } ; } get pageChange() { return this._pageChange; } set pageChange(ev) { if (this._pageChange_wrapped !== null) { this.i.pageChange = delegateRemove(this.i.pageChange, this._pageChange_wrapped); this._pageChange_wrapped = null; this._pageChange = null; } this._pageChange = ev; this._pageChange_wrapped = (o, e) => { let outerArgs = new IgrNumberEventArgs(); outerArgs._provideImplementation(e); if (this.beforePageChange) { this.beforePageChange(this, outerArgs); } if (this._pageChange) { this._pageChange(this, outerArgs); } }; this.i.pageChange = delegateCombine(this.i.pageChange, this._pageChange_wrapped); if (this.i.pageChangeChanged) { this.i.pageChangeChanged(); } ; } get paging() { return this._paging; } set paging(ev) { if (this._paging_wrapped !== null) { this.i.paging = delegateRemove(this.i.paging, this._paging_wrapped); this._paging_wrapped = null; this._paging = null; } this._paging = ev; this._paging_wrapped = (o, e) => { let outerArgs = new IgrPageCancellableEventArgs(); outerArgs._provideImplementation(e); if (this.beforePaging) { this.beforePaging(this, outerArgs); } if (this._paging) { this._paging(this, outerArgs); } }; this.i.paging = delegateCombine(this.i.paging, this._paging_wrapped); if (this.i.pagingChanged) { this.i.pagingChanged(); } ; } get pagingDone() { return this._pagingDone; } set pagingDone(ev) { if (this._pagingDone_wrapped !== null) { this.i.pagingDone = delegateRemove(this.i.pagingDone, this._pagingDone_wrapped); this._pagingDone_wrapped = null; this._pagingDone = null; } this._pagingDone = ev; this._pagingDone_wrapped = (o, e) => { let outerArgs = new IgrPageEventArgs(); outerArgs._provideImplementation(e); if (this.beforePagingDone) { this.beforePagingDone(this, outerArgs); } if (this._pagingDone) { this._pagingDone(this, outerArgs); } }; this.i.pagingDone = delegateCombine(this.i.pagingDone, this._pagingDone_wrapped); if (this.i.pagingDoneChanged) { this.i.pagingDoneChanged(); } ; } }