【问题标题】:ag-grid angular access selectionController.getLastSelectedNode()ag-grid 角度访问 selectionController.getLastSelectedNode()
【发布时间】:2019-12-06 22:05:24
【问题描述】:

我需要从 gridApi 检索最后选择的节点。 我设法在 gridApi 中找到了一个私有成员变量,selectionController

此控制器有一个名为 getLastSelectedNode() 的函数。 selectionController.getLastSelectedNode().

这是来自 ag-grid 库的相应源代码 selectionController.ts

我可以做一些hacky代码,以便从gridApi访问私有成员,如下所示: this.gridApi['selectionController'].lastSelectedNode.data

但是,我对这种方法并不满意。 有谁知道是否可以像在 ag-grid 库中那样将控制器注入到我的服务中? 我有兴趣在我的服务中添加一些类似的代码:

@Autowired('selectionController') private selectionController: SelectionController;

【问题讨论】:

    标签: angular ag-grid ag-grid-angular


    【解决方案1】:

    你在寻找这样的东西吗?

    lastSelectedNodes;
    [...]
    this.gridOptions = {
      onSelectionChanged: (event: SelectionChangedEvent) => {
        if (this.lastSelectedNodes) {
          const lastAdded = event.api.getSelectedNodes().filter(x => !this.lastSelectedNodes.includes(x));
          console.log("last selected node: ", lastAdded);
        }
        this.lastSelectedNodes = event.api.getSelectedNodes();
      }
    }
    

    【讨论】:

    • 我需要像gridApi.lastSelectedNode.data 这样简单的东西我有上面的代码。在我的问题中,我提到 gridApi 的数据仅供私人使用。如果能公开访问,那就太好了。
    猜你喜欢
    • 2018-06-02
    • 2018-09-19
    • 1970-01-01
    • 1970-01-01
    • 2020-06-14
    • 2017-01-24
    • 2019-04-14
    • 2019-10-15
    • 2019-09-11
    相关资源
    最近更新 更多