table.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. export default {
  2. template: "<div></div>",
  3. mounted() {
  4. this.gridOptions = {
  5. ...this.options,
  6. onGridReady: (params) => params.api.sizeColumnsToFit(),
  7. };
  8. this.grid = new agGrid.Grid(this.$el, this.gridOptions);
  9. },
  10. methods: {
  11. update_grid() {
  12. replaceObject(this.options, this.gridOptions);
  13. this.gridOptions.api.refreshCells();
  14. },
  15. call_api_method(name, ...args) {
  16. this.gridOptions.api[name](...args);
  17. },
  18. },
  19. props: {
  20. options: Object,
  21. },
  22. };
  23. function replaceArray(source, target) {
  24. for (let i = 0; i < source.length; i++) {
  25. if (typeof source[i] === "object") {
  26. replaceObject(source[i], target[i]);
  27. } else if (typeof source[i] === "array") {
  28. replaceArray(source[i], target[i]);
  29. } else {
  30. target[i] = source[i];
  31. }
  32. }
  33. }
  34. function replaceObject(source, target) {
  35. for (let key in source) {
  36. if (typeof source[key] === "object") {
  37. replaceObject(source[key], target[key]);
  38. } else if (typeof source[key] === "array") {
  39. replaceArray(source[key], target[key]);
  40. } else {
  41. target[key] = source[key];
  42. }
  43. }
  44. }