Angular ag-grid - how do I collect a header clicked event?

孤者浪人 提交于 2021-01-29 13:38:05

问题


I want to catch an event from a header click in a non-sorted column and I can't figure out how to do so. I can get it if I turn on sorting with onSortChanged but if I do that, I can't suppress the sort/turn off the arrows form displaying. Any ideas how to simply grab the a header clicked event? Thank you.


回答1:


To achieve expected result, use below option of using addEventListener on Header cell

 this.gridOptions = <GridOptions>{
          enableSorting: false,
          enableFilter: true,
          onGridReady: (params) =>{
            const header = document.querySelectorAll('.ag-header-cell');
        console.log(header);
        header.forEach(v => {
          v.addEventListener('click', function(event){
            console.log("clicked")
          })
        });
          }
        };

working code for reference- https://stackblitz.com/edit/angular-ag-grid-angular-54vy3p?file=app/my-grid-application/my-grid-application.component.ts

Currently there is only rowClick events and no Column header events



来源:https://stackoverflow.com/questions/57811417/angular-ag-grid-how-do-i-collect-a-header-clicked-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!