I am new to angular and ngx datatable. how to get row data on mouse click event
onClick(event) {
// I need to get row data here
}
I am new to angular and ngx datatable. how to get row data on mouse click event
onClick(event) {
// I need to get row data here
}
Just use (activate)="onActivate($event)" property on ngx-datatable like this
<ngx-datatable #table
....
(activate)="onActivate($event)"
....
>
Then in TS file, use this method
onActivate(event) {
if(event.type == 'click') {
console.log(event.row);
}
}
(activate)="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);
}
(activate)
event, you will get event
, row
, rowElement
, type
(select)
event, you will only get selected
They have an example right here in the documentation
http://swimlane.github.io/ngx-datatable/#single-selection
Source code:
https://github.com/swimlane/ngx-datatable/blob/master/demo/selection/selection-single.component.ts
© 2022 - 2024 — McMap. All rights reserved.