diprokon / ng-table-virtual-scroll

Virtual Scroll for Angular Material Table
https://diprokon.github.io/ng-table-virtual-scroll
MIT License
134 stars 42 forks source link

Getting error "Cannot read property '_switchDataSource' of undefined" with Angular 11 #59

Open DwightTheMan opened 3 years ago

DwightTheMan commented 3 years ago

Getting error: Cannot read property '_switchDataSource' of undefined at TableItemSizeDirective.ngAfterContentInit (ng-table-virtual-scroll.js:168)

with Angular 11. Table data doesn't load.

diprokon commented 3 years ago

Hi! Can You provide some code example with the issue?

leahtz commented 3 years ago

I have the same error in angular 9 my code: <cdk-virtual-scroll-viewport tvsItemSize="itemsize" [ngStyle]="height: totalheight"> <table mat-table [dataSource]="dataSource">

</table>

initilaize dataSource: this.dataSource=new TableVirtualScrollDataSource(this._data);

leahtz commented 3 years ago

update: my code usin ng-template like this: <cdk-virtual-scroll-viewport tvsItemSize="itemsize" [ngStyle]="height: totalheight">

... <ng-template #theTable> <mat-table [dataSource]=datasource ...

jdessaint commented 3 years ago

Hello, here an example of the issue. I'm started from the base example in the provided documentation. I moved the table in <ng-template> and I called this with *ngTemplateOutlet in the <cdk-virtual-scroll-viewport>.

javidg07 commented 2 years ago

Hello @diprokon it works fine in development but when we run test case we get the same issue with **_switchDataSource of undefined from ngViewContentInit ....** <cdk-virtual-scroll-viewport tvsItemSize [ngStyle]="height: totalheight"> but if we add just itemSize ="20" testcase runs but it fails to load the data without any error in chrome.

armorildo commented 2 years ago

I had the same issue with the mat-table with virtual scroll. The code structure was something like:

<ng-template>
  <cdk-virtual-scroll-viewport tvsItemSize="itemsize">
    <table mat-table [dataSource]="dataSource">

What worked for me was placing the virtual scroll viewport inside a container div, and not directly inside the ng-template, like below:

<ng-template>
  <div>
    <cdk-virtual-scroll-viewport tvsItemSize="itemsize">
      <table mat-table [dataSource]="dataSource">