igniteui-react-grids
Version:
Ignite UI React grid components.
308 lines (305 loc) • 8.88 kB
JavaScript
import * as React from 'react';
import { delegateCombine, delegateRemove } from "igniteui-react-core";
import { toSpinal, brushToString, stringToBrush, initializePropertiesFromCss, NamePatcher, isValidProp, getModifiedProps } from "igniteui-react-core";
import { ReactRenderer } from "igniteui-react-core";
import { FontInfo } from "igniteui-react-core";
import { BrowserExecutionContext } from "./BrowserExecutionContext";
import { Pager } from "./Pager";
import { IgrPageChangedEventArgs } from "./igr-page-changed-event-args";
let PagerStylingDefaults = {};
export class IgrDataGridPager extends React.Component {
_getMainRef(ref) {
this._elRef = ref;
if (this._elRef) {
this._renderer = new ReactRenderer(this._elRef, document, true, PagerStylingDefaults, null);
this.i.provideContainer(this._renderer);
this._styling(this._elRef, this);
}
else {
this.i.provideContainer(null);
}
}
render() {
let div = React.createElement("div", {
className: "ig-data-grid-pager igr-data-grid-pager",
ref: this._getMainRef,
});
return div;
}
createImplementation() {
return new Pager();
}
get i() {
return this._implementation;
}
onImplementationCreated() {
}
constructor(props) {
super(props);
this._renderer = null;
this._dataSource = null;
this.__p = null;
this._hasUserValues = new Set();
this._stylingContainer = null;
this._stylingParent = null;
this._inStyling = false;
this._pageChanged = null;
this._pageChanged_wrapped = null;
if (this._styling) {
NamePatcher.ensureStylablePatched(Object.getPrototypeOf(this));
}
this._getMainRef = this._getMainRef.bind(this);
var root;
root = this._container;
this.requestRender = this.requestRender.bind(this);
this._implementation = new Pager();
this._implementation.executionContext = new BrowserExecutionContext(null);
this._implementation.externalObject = this;
this.initializeProperties();
}
requestRender() {
this.setState({});
}
initializeContent() {
if (this._dataSource) {
this.i.itemsSource = this._dataSource;
}
}
destroy() {
this._renderer.destroy();
}
componentWillUnmount() {
}
componentDidMount() {
this.initializeContent();
}
initializeProperties() {
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;
}
containerResized() {
//var width = this._container.clientWidth;
//var height = this._container.clientHeight;
}
;
get actualDataSource() {
return this.i.actualDataSource;
}
/**
* Gets or sets the data used by the pager.
* */
set dataSource(value) {
this._dataSource = value;
if (this.i != null) {
this.i.itemsSource = this._dataSource;
}
}
get dataSource() {
return this._dataSource;
}
/**
* Gets or sets the target grid for the pager.
* */
set targetGrid(value) {
value == null ? this.i.targetGrid = null : this.i.targetGrid = value.i;
}
get targetGrid() {
if (this.i.targetGrid == null) {
return null;
}
return this.i.targetGrid.externalObject;
}
get pagerText() {
return this.i.a9;
}
set pagerText(v) {
this.i.a9 = v;
}
/**
* Gets or sets the page size.
*/
get pageSize() {
return this.i.ao;
}
set pageSize(v) {
this.i.ao = +v;
}
/**
* Gets the page count.
*/
get pageCount() {
return this.i.an;
}
set pageCount(v) {
this.i.an = +v;
}
/**
* Gets or sets the current page for the pager.
*/
get currentPage() {
return this.i.ak;
}
set currentPage(v) {
this.i.ak = +v;
}
/**
* Gets or sets the font to use for content cells
*/
get textStyle() {
if (this.i.s == null) {
return null;
}
return this.i.s.fontString;
}
set textStyle(v) {
let fi = new FontInfo();
fi.fontString = v;
this.i.s = fi;
}
/**
* Gets or sets the background color to use.
*/
get background() {
return brushToString(this.i.ca);
}
set background(v) {
this.i.ca = stringToBrush(v);
}
/**
* Gets or sets the border color around the grid.
*/
get border() {
return brushToString(this.i.border);
}
set border(v) {
this.i.border = stringToBrush(v);
}
findByName(name) {
if (this.findEphemera) {
if (name && name.indexOf("@@e:") == 0) {
return this.findEphemera(name);
}
}
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("DataGridPager");
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;
}
nextPage() {
this.i.bn();
}
previousPage() {
this.i.by();
}
firstPage() {
this.i.bk();
}
lastPage() {
this.i.bm();
}
provideContainer(container) {
this.i.provideContainer(container);
}
/**
* Exports visual information about the current state of the grid.
*/
exportVisualModel() {
let iv = this.i.as();
return (iv);
}
/**
* Returns a serialized copy of the exported visual model
*/
exportSerializedVisualModel() {
let iv = this.i.az();
return (iv);
}
/**
* Event called when the page has changed.
*/
get pageChanged() {
return this._pageChanged;
}
set pageChanged(ev) {
if (this._pageChanged_wrapped !== null) {
this.i.pageChanged = delegateRemove(this.i.pageChanged, this._pageChanged_wrapped);
this._pageChanged_wrapped = null;
this._pageChanged = null;
}
this._pageChanged = ev;
this._pageChanged_wrapped = (o, e) => {
let outerArgs = new IgrPageChangedEventArgs();
outerArgs._provideImplementation(e);
if (this.beforePageChanged) {
this.beforePageChanged(this, outerArgs);
}
if (this._pageChanged) {
this._pageChanged(this, outerArgs);
}
};
this.i.pageChanged = delegateCombine(this.i.pageChanged, this._pageChanged_wrapped);
;
}
}