question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

expandAllRows does not work from ngOnInit or ngAfterViewInit

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:5
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
varminascommented, Jan 15, 2020

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);
1reaction
stephencawoodcommented, Jan 28, 2018

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();
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

ngAfterViewInit is not working or am I doing something wrong
So basically, I'm using ngAfterViewInint() function to scroll to the current item, after the view complete loaded. Inside ngOnInit() , if I am ......
Read more >
ngAfterViewInit Example | Angular - StackChief
In the example above, ngAfterViewInit() gets called one time after ngDoCheck. Triggering the clickMe() function WILL NOT trigger ...
Read more >
Lifecycle hooks - Angular
A component instance has a lifecycle that starts when Angular instantiates the component class and renders the component view along with its child...
Read more >
Angular Debugging "Expression has changed": Explanation ...
With this new version, there is no modification of the template data in the ngAfterViewInit() lifecycle hook, and so the problem does not...
Read more >
Angular lifecycle hooks explained - LogRocket Blog
DoCheck is not run on an event like OnInit and OnChanges , which are called when a change in input properties occurs or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found