Ag-grid Angular如何在页眉上获取单击事件? [英] Ag-grid Angular How to get click events on Header?
问题描述
< ag-grid-angular> ;
-Component为点击单元格提供了多个事件(例如 cellDoubleClicked )。这些事件不会触发标题点击,我无法找到任何特定于标题点击的事件。
The <ag-grid-angular>
-Component offers multiple events for clicks on cells (e.g. cellDoubleClicked). Those don't get triggered for header clicks and I was unable to find any events specific for header clicks.
这个问题过去已经被其他人问过,所以没有答案,所以我认为没有任何内置的方法。
This question was already asked by someone else in the past and not answered, so I don't think, there's any built in way.
我正在与另一个库一起为应用程序提供上下文菜单,但是我想区分标题和常规单元格的不同上下文菜单。因此,仅侦听默认的角度单击事件(在整个网格组件上)无济于事,因为我需要单击的列/单元格。
I'm working with another library to supply context menus for the application, but I want to differentiate between different context menus for headers and regular cells. So just listening to the default angular click event (on the whole grid component) doesn't help, because I need the clicked column/cell.
当前使用的是ag-grid 15.0.0,但是我在当前文档中也没有找到任何内容。
For reference I'm currently using ag-grid 15.0.0, but I also didn't find anything in the current documentation.
推荐答案
我认为,如果您定义标头组件,这是可能的(请参阅:标题组件)。在标头组件的模板中,您可以创建 div
元素(或任何其他容器元素)并定义(单击)
事件处理程序。这对我有用:
I think this may be possible if you define the header component (see: Header Components). In your template for the header component you can create a div
element (or any other container element) and define the (click)
event handler. This worked for me:
<div (click)='onHeaderClick($event)'>
<p>Name</p>
</div>
(当然,您可能希望将参数中的标题传递给 agInit()
方法,因为您不想为每个标头创建单独的标头组件!)
(Of course you'd probably want to pass the header title in the parameters to the agInit()
method, since you wouldn't want to create a separate header component for every header!)
这篇关于Ag-grid Angular如何在页眉上获取单击事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!