swimlane / ngx-datatable

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

expandAllRows does not work from ngOnInit or ngAfterViewInit #929

Open on3al opened 6 years ago

on3al commented 6 years ago

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

amcdnl commented 6 years ago

Thanks for raising this issue.

dalbir commented 6 years ago

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.

carotene4035 commented 6 years ago

@dalbir

Any property to set by default expended or collapsible

I think so too.

alekseytimonin commented 6 years ago

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

padilla-jm commented 6 years ago

I'm having this same issue.

stephencawood commented 6 years ago

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();
    }
}
varminas commented 4 years ago

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);
stanislavromanov commented 9 months ago

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