我是angular和ngx数据表的新手。如何在鼠标单击事件中获取行数据
onClick(event) {
// I need to get row data here
}
答案 0 :(得分:2)
只需像这样在ngx-datatable上使用(activate)=“ onActivate($ event)”属性
<ngx-datatable #table
....
(activate)="onActivate($event)"
....
>
然后在TS文件中,使用此方法
onActivate(event) {
if(event.type == 'click') {
console.log(event.row);
}
}
答案 1 :(得分:0)
他们在文档中有一个示例
http://swimlane.github.io/ngx-datatable/#single-selection
源代码:
https://github.com/swimlane/ngx-datatable/blob/master/demo/selection/selection-single.component.ts
答案 2 :(得分:0)
(activated)="onActivate($event)"
OR
(select)="onSelect($event)"
onActivate(event) {
if(event.type == 'click') {
console.log(event.row);
}
}
onSelect(event) {
//event.type is undefined, use below:
console.log(event.selected);
}
(activated)
事件,则会得到event
,row
,rowElement
,type
(select)
事件,则只会得到selected