【问题标题】:How to set global properties for ag-Grid?如何为 ag-Grid 设置全局属性?
【发布时间】:2016-09-14 06:46:04
【问题描述】:

假设我需要为我的ag-grid 设置height。我必须在列配置上设置它,就像那样(在 Angular 控制器中):

this.myAgGridOptions = {
  columnDefs: ...,
  rowData: ...,
  headerHeight: 42,
  rowHeight: 42
}

现在,如果我的整个应用程序中有 10 个不同的 agGrid,有没有办法为所有这些属性设置一次,而不是为每个 agGrid 声明设置一次?

我的问题是针对 Angular 1 版本的 AgGrid,但如果该解决方案可以用于任何版本的 AgGrid,那就太好了。

谢谢

【问题讨论】:

    标签: angularjs ag-grid


    【解决方案1】:

    最好的方法是使用 angular 提供的extend method

    所以你可以有这样的东西:

    this.GlobalAgGridOptions = {
      headerHeight: 42,
      rowHeight: 42
    }
    
    this.myAgGridOptionsOne = {
        rowData: rowDataOne,
        columnDefs: columnDefsOne
    }
    
    this.myAgGridOptionsTwo = {
        rowData: rowDataTwo,
        columnDefs: columnDefsTwo
    }
    
    angular.extends(this.mygridOptionsOne, this.GlobalOptions);
    angular.extends(this.mygridOptionsTwo, this.GlobalOptions);
    

    现在两个网格选项都应该有全局选项。我想我假设您将为您计划创建的每个网格创建一些不同的 gridOptions。我希望我猜对了

    【讨论】:

    • 您好,感谢您的回答。我通过创建一个包含全局 agGrid 选项的 Angular 常量来解决我的问题。
    猜你喜欢
    • 2019-02-24
    • 2017-01-07
    • 2019-01-18
    • 2016-02-20
    • 2018-05-25
    • 2020-11-18
    • 2020-10-22
    • 1970-01-01
    • 2019-07-14
    相关资源
    最近更新 更多