ngx-datatable icon indicating copy to clipboard operation
ngx-datatable copied to clipboard

expandAllRows does not work from ngOnInit or ngAfterViewInit

Open on3al opened this issue 8 years ago • 8 comments

I'm submitting a ... (check one with "x")

[X] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, post on Stackoverflow or Gitter

Current behavior Calling table.rowDetail.expandAllRows() or collapseAllRows() only works after the view is fully initialized (i.e calling from a button click).

When called from ngOnInit or ngAfterViewInit, calling exapndAllRows() does not do anything, the rows remain in collapsed state.

Expected behavior Calling exapndAllRows from in ngOnInit and certainly in ngAfterViewInit, should start the rows in an expanded state.

Reproduction of the problem Modify the demo project you have showing collapse/expand to call expand from ngInit to see behavior What is the motivation / use case for changing the behavior? In many cases, the preferred state is to have all rows expanded by default.

Please tell us about your environment: Windows 10, Angular 4.1, Typscript 2.4.2

  • Table version: 0.8.x Yes, using 10.1.0 still see issue

  • Angular version: 2.0.x Yes, using angular 4.3 still an issue.

  • Browser: [all ]

  • Language: [all | TypeScript X.X | ES6/7 | ES5] Typescript 2.4.2

on3al avatar Aug 23 '17 18:08 on3al

Thanks for raising this issue.

amcdnl avatar Aug 23 '17 23:08 amcdnl

Is there any option to watch table is rendered so that we call ExpandAll event after load.

Or Any property to set by default expended or collapsible.

dalbir avatar Aug 24 '17 11:08 dalbir

@dalbir

Any property to set by default expended or collapsible

I think so too.

carotene4035 avatar Oct 19 '17 07:10 carotene4035

I have the same issue. Need to subscribe to OnLoaded event to expand relevant rows. Any updates? Workarounds?

alekseytimonin avatar Dec 14 '17 15:12 alekseytimonin

I'm having this same issue.

padilla-jm avatar Dec 20 '17 18:12 padilla-jm

I also want the rows to start expanded by default. I had to workaround this issue using the code below. However, it runs the check about five times (which makes it tough to ever collapse the rows) and I'd appreciate this bug being fixed. (Note this is the Angular Universal version)

@ViewChild('myTable') tableRef: any;
...
ngAfterViewChecked() {
    if (isPlatformBrowser(this.platformId) && this.rows.length > 0) {
        this.tableRef.rowDetail.expandAllRows();
    }
}

stephencawood avatar Jan 28 '18 18:01 stephencawood

Are there any updates/solutions for this bug? I have used setTimeout function as a workaround, but this is really dirty:

@ViewChild(DatatableComponent) private table: DatatableComponent;
constructor(private cdRef: ChangeDetectorRef) {}

setTimeout(() => {
    this.table.rowDetails.toggleExpandedRow(ROW);
    this.cdRef.detectChanges();
}, 1000);

varminas avatar Jan 15 '20 20:01 varminas

In reality this is an Angular bug. ngAfterViewInit does not do what it says it does in documentation.

stanislavromanov avatar Sep 28 '23 06:09 stanislavromanov