Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get row data onSelect event in ngx datatable

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 
}
like image 553
user3714269 Avatar asked Aug 21 '18 13:08

user3714269


2 Answers

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);
    }
}
like image 131
karan sharma Avatar answered Oct 17 '22 11:10

karan sharma


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
like image 32
sky91 Avatar answered Oct 17 '22 10:10

sky91