Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function () {
- 'use strict';
- agGrid.LicenseManager.setLicenseKey('A valid License');
- var ComponentUtil = agGrid.ComponentUtil;
- /**
- * Takes an array of strings and returns an object containing those strings as properties assigned the provided value
- *
- * @param {any} array
- * @param {any} value
- * @returns object
- */
- function assignValueToAllKeys(array, value) {
- return array.reduce(function (acc, curr) {
- acc[curr] = value;
- return acc;
- }, {});
- }
- /**
- * Assign all inputs and outputs to the grid component based on those provided by the AgGrid library
- *
- * @returns object
- */
- function getBindings() {
- return _.merge({
- gridType: '<',
- gridOptions: '<'
- },
- assignValueToAllKeys(ComponentUtil.ALL_PROPERTIES, '<'),
- assignValueToAllKeys(ComponentUtil.EVENTS, '&'));
- }
- angular
- .module('grid')
- .component('agGrid', {
- bindings: getBindings(),
- controller: ['$element', '$scope', '$compile', '$attrs', 'i18n', 'GridTypeService', AgGridComponent]
- });
- function AgGridComponent($element, $scope, $compile, $attrs, i18n, GridTypeService) {
- this._intialized = false;
- this._destroyed = false;
- var grid;
- this.$onInit = function () {};
- this.$postLink = function () {
- this.gridOptions = _.merge({}, this.gridOptions, GridTypeService.lookupGridOptions(this.gridType));
- this.gridOptions = ComponentUtil.copyAttributesToGridOptions(this.gridOptions, this);
- var gridParams = {
- $scope: $scope,
- $compile: $compile,
- quickFilterOnScope: this.gridOptions.quickFilterText,
- globalEventListener: this.globalEventListener.bind(this)
- };
- if (this.columns && this.columns.length > 0) {
- this.gridOptions.columnDefs = this.columns.map(function (column) {
- return column.toColDef();
- });
- }
- grid = new agGrid.Grid($element[0], this.gridOptions, gridParams);
- if (this.gridOptions.api) {
- this.api = this.gridOptions.api;
- }
- if (this.gridOptions.columnApi) {
- this.columnApi = this.gridOptions.columnApi;
- }
- this._intialized = true;
- };
- this.$onChanges = function (changes) {
- if (this._intialized) {
- ComponentUtil.processOnChange(changes, this.gridOptions, this.api, this.columnApi);
- }
- };
- this.$onDestroy = function () {
- if (this._intialized) {
- // TODO - Investigate - this is how the Angular 2 version handles destroy - the Angular 1 version remains uncommented
- this._destroyed = true;
- // this.api.destroy();
- grid.destroy();
- grid = null;
- }
- };
- this.globalEventListener = function (eventType, event) {
- if (this._destroyed) {
- return;
- }
- var emitter = this[eventType];
- if (emitter) {
- emitter({
- $event: event
- });
- }
- };
- }
- })();
Add Comment
Please, Sign In to add comment