8

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 
}
user3714269
  • 129
  • 1
  • 2
  • 4
  • 2
    You should really do more research or attempt to google your questions first. If your question requires something further then you need to add in depth explanation. – canpan14 Aug 21 '18 at 13:32

3 Answers3

23

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);
    }
}
karan sharma
  • 605
  • 4
  • 18
2

component.html file


(activate)="onActivate($event)"

OR

(select)="onSelect($event)"

component.ts file

onActivate(event) {
    if(event.type == 'click') {
        console.log(event.row);
    }
}

onSelect(event) {
    //event.type is undefined, use below:

    console.log(event.selected);
}

Note

  • If you are using (activate) event, you will get event, row, rowElement, type
  • If you are using (select) event, you will only get selected
sky91
  • 3,060
  • 2
  • 19
  • 26
1

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

canpan14
  • 1,181
  • 1
  • 14
  • 36