agGridVue.js 2.6 KB
Newer Older
ibiz's avatar
ibiz committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _vue = _interopRequireDefault(require("vue"));

var _agGridCommunity = require("ag-grid-community");

var _vueFrameworkFactory = require("./vueFrameworkFactory");

var _vueFrameworkComponentWrapper = require("./vueFrameworkComponentWrapper");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var watchedProperties = {};
var props = {
  gridOptions: {
    default: function _default() {
      return {};
    }
  }
};

_agGridCommunity.ComponentUtil.ALL_PROPERTIES.forEach(function (propertyName) {
  props[propertyName] = {};

  watchedProperties[propertyName] = function (val, oldVal) {
    this.processChanges(propertyName, val, oldVal);
  };
});

_agGridCommunity.ComponentUtil.EVENTS.forEach(function (eventName) {
  props[eventName] = {};
});

var _default2 = _vue.default.extend({
  render: function render(h) {
    return h('div');
  },
  props: props,
  data: function data() {
    return {
      _initialised: false,
      _destroyed: false
    };
  },
  methods: {
    globalEventListener: function globalEventListener(eventType, event) {
      if (this._destroyed) {
        return;
      } // generically look up the eventType


      var emitter = this[eventType];

      if (emitter) {
        emitter(event);
      }
    },
    processChanges: function processChanges(propertyName, val, oldVal) {
      if (this._initialised) {
        var changes = {};
        changes[propertyName] = {
          currentValue: val,
          previousValue: oldVal
        };

        _agGridCommunity.ComponentUtil.processOnChange(changes, this.gridOptions, this.gridOptions.api, this.gridOptions.columnApi);
      }
    }
  },
  mounted: function mounted() {
    var frameworkComponentWrapper = new _vueFrameworkComponentWrapper.VueFrameworkComponentWrapper(this);
    var vueFrameworkFactory = new _vueFrameworkFactory.VueFrameworkFactory(this.$el, this);

    var gridOptions = _agGridCommunity.ComponentUtil.copyAttributesToGridOptions(this.gridOptions, this);

    var gridParams = {
      globalEventListener: this.globalEventListener.bind(this),
      frameworkFactory: vueFrameworkFactory,
      seedBeanInstances: {
        frameworkComponentWrapper: frameworkComponentWrapper
      }
    };
    new _agGridCommunity.Grid(this.$el, gridOptions, gridParams);
    this._initialised = true;
  },
  watch: watchedProperties,
  destroyed: function destroyed() {
    if (this._initialised) {
      if (this.gridOptions.api) {
        this.gridOptions.api.destroy();
      }

      this._destroyed = true;
    }
  }
});

exports.default = _default2;