UNPKG

@progress/kendo-grid-react-wrapper

Version:

Kendo UI Grid wrapper for React

103 lines 4.59 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); var React = require("react"); var kendo_base_component_react_wrapper_1 = require("@progress/kendo-base-component-react-wrapper"); var util_1 = require("./util"); var GridColumn_1 = require("./GridColumn"); var Grid = /** @class */ (function (_super) { __extends(Grid, _super); function Grid() { return _super !== null && _super.apply(this, arguments) || this; } Grid.prototype.componentDidMount = function () { var domNode = this.domNode; var _a = this.enhanceProps(this.props), gridConfiguration = _a._configuration, gridEvents = _a._gridEvents, dataSource = _a.dataSource, children = _a.children; var options = Object.assign({}, gridConfiguration, gridEvents, { dataSource: dataSource }); var columns = React.Children .toArray(children) .filter(function (child) { return child && child.type === GridColumn_1.default; }) .map(function (child) { return Object.assign({}, child.props); }); if (columns.length > 0) { options = Object.assign(options, { columns: columns }); } if (domNode) { this.widgetInstance = new kendo.ui.Grid(domNode, options); _super.prototype.componentDidMount.call(this); } this.didMount = true; this.oldProps = this.props; }; Grid.prototype.componentDidUpdate = function () { this.oldProps = this.props; }; Grid.prototype.render = function () { if (this.didMount) { var nextOptions = this.enhanceProps(this.props); var currentOptions = this.enhanceProps(this.oldProps); this.setDataSource(this.props.dataSource); util_1.reconcileConfiguration(currentOptions._configuration, nextOptions._configuration, this.widgetInstance); util_1.reconcileEvents(currentOptions._gridEvents, nextOptions._gridEvents, this.widgetInstance); } var domChild = React.Children .toArray(this.props.children) .filter(function (child) { return child && (child.type === 'div' || child.type === 'table'); }) .shift(); return domChild ? React.cloneElement(domChild, __assign({}, domChild.props, { ref: this.elementRef })) : React.createElement("div", { ref: this.elementRef }); }; Grid.prototype.setDataSource = function (dataSource) { if (this.widgetInstance.options.dataSource !== dataSource) { this.widgetInstance.setDataSource(dataSource instanceof Array ? new kendo.data.DataSource({ data: dataSource }) : dataSource); } }; Grid.prototype.enhanceProps = function (props) { var _configuration = Object.create(null); var _gridEvents = Object.create(null); Object.keys(props) .map(function (key) { if (util_1.configuration.indexOf(key) !== -1) { Object.defineProperty(_configuration, key, { enumerable: true, value: props[key] }); } else if (util_1.events.indexOf(key) !== -1) { Object.defineProperty(_gridEvents, key, { enumerable: true, value: props[key] }); } }); return __assign({ _configuration: _configuration, _gridEvents: _gridEvents }, props); }; return Grid; }(kendo_base_component_react_wrapper_1.default)); exports.default = Grid; //# sourceMappingURL=index.js.map