swimlane / ngx-datatable

✨ A feature-rich yet lightweight data-table crafted for Angular
http://swimlane.github.io/ngx-datatable/
MIT License
4.63k stars 1.68k forks source link

Row detail expand/collapse is not working as expected #1667

Open Md-Aman opened 5 years ago

Md-Aman commented 5 years ago

The scenario is like this I am calling the expand row function to expand the rows (setting by default) once the component will load by using the ngAfterViewChecked() hook. It is working as per discussed here https://github.com/swimlane/ngx-datatable/issues/1303 But I am facing difficulty to collapse the rows by clicking a single row. The function is calling without any error but the row is not collapsing.

import { ChangeDetectorRef } from '@angular/core';

@ViewChild('myTable') table: any;

constructor(private cdRef:ChangeDetectorRef) {}

ngAfterViewChecked() { if (this.table && this.table.rowDetail) { this.table.rowDetail.expandAllRows(); this.cdRef.detectChanges(); } }

toggleExpandRow(row) { //function is calling but row is not collapsing console.log('get row', row); this.table.rowDetail.toggleExpandRow(row); }

You may check the demo here https://stackblitz.com/edit/ngx-datatable-row-detail

Andrew240 commented 5 years ago

Hi @Md-Aman You only need to change the isCheck value into ngAfterViewChecked(). How this:

ngAfterViewChecked() { if (this.table && this.table.rowDetail) { this.isCheck = true; // this.table.rowDetail.expandAllRows(); // this.cdRef.detectChanges(); } } Screen Shot 2019-07-12 at 1 18 23 PM