How to get row data onSelect event in ngx datatable
Asked Answered
A

3

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 
}
Alfredoalfresco answered 21/8, 2018 at 13:0 Comment(1)
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.Anestassia
I
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);
    }
}
Impoverish answered 31/12, 2018 at 7:46 Comment(0)
M
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
Micromho answered 22/5, 2019 at 4:47 Comment(1)
(activate), not (activated)Splendiferous
A
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

Anestassia answered 21/8, 2018 at 13:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.