【问题标题】:How to emit an event within a NoRowsOverlayComponent?如何在 NoRowsOverlayComponent 中发出事件?
【发布时间】:2020-09-04 01:08:27
【问题描述】:

我想显示一个包含按钮的覆盖容器。单击按钮时,应将事件传播到父组件。在我的研究中,我发现 设置“noRowsOverlayComponentParams”的选项在我的版本 (22.1.2) 中不存在。我也无法获取按钮的点击事件。

是否有解决我的问题的解决方法或设置?

PS:组件显示正确,但我无法获取点击事件。

网格选项:

let options: any = {
      defaultColDef: {
        sortable: true,
        filter: true,
        resizable: true
      },
      suppressPaginationPanel: true,
      columnDefs: [...],
      paginationPageSize: 10,
      context: { componentParent: this},
      domLayout: 'normal',
      enableCellTextSelection: true,
      autoSizePadding: 2,
      noRowsOverlayComponent: 'myNoRowsComponent',
      frameworkComponents: {
        myNoRowsComponent: MyNoRowsComponent
      }
    };

MyNoRowsComponent.ts:

import { Component } from '@angular/core';
import { INoRowsOverlayAngularComp } from '@ag-grid-community/angular';
import { INoRowsOverlayParams, IAfterGuiAttachedParams } from '@ag-grid-enterprise/all-modules';

@Component({
  selector: 'app-my-no-rows',
  templateUrl: './my-no-rows.component.html',
  styleUrls: ['./my-no-rows.component.scss']
})
export class MyNoRowsComponent implements INoRowsOverlayAngularComp {

  params: any;

  agInit(params: INoRowsOverlayParams): void {
    this.params = params;

  }

  clickImport() {
    // this.params.context.componentParent.clickButton(); // <-- here I want to emit an event
  }

  afterGuiAttached?(params?: IAfterGuiAttachedParams): void { }

}

MyNoRowsComponent.html:

<button (click)="clickImport()">My Button</Button>

【问题讨论】:

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


    【解决方案1】:

    对于那些搜索这个问题的人,我发现指针事件设置为禁用覆盖。 只需将其添加到您的按钮类:

    pointer-events: all;
    

    【讨论】:

    • 这对我有用。谢谢
    【解决方案2】:

    我将创建一个共享服务,将其注入到父组件和覆盖组件中。

    共享服务可以公开一个“通知”方法,该方法在主题上调用 next。 它还可以公开将 Subject 作为 Observable 返回的“getNotifications”。

    然后父组件可以订阅Observable, 并且覆盖层可以调用'notify'方法,将数据传递给父组件。

    【讨论】:

    • 我知道,但问题是我什至无法从按钮获得点击事件(点击功能永远不会被触发 -> 我已经测试并调试过了)。
    • @JuNe 你找到方法了吗?我也在尝试同样的场景
    • @GillesVercammen 目前没有。我们现在在我们的应用程序中删除了该按钮,因为它对我们来说没有很高的优先级。也许我们稍后会尝试使用更新的版本。
    猜你喜欢
    • 2018-05-19
    • 1970-01-01
    • 1970-01-01
    • 2021-07-18
    • 1970-01-01
    • 1970-01-01
    • 2017-12-25
    • 2022-10-15
    • 1970-01-01
    相关资源
    最近更新 更多