Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite-scroll TS compile error #231

Open
Hintalo opened this issue Feb 15, 2022 Discussed in #230 · 0 comments
Open

Infinite-scroll TS compile error #231

Hintalo opened this issue Feb 15, 2022 Discussed in #230 · 0 comments

Comments

@Hintalo
Copy link

Hintalo commented Feb 15, 2022

Discussed in #230

Originally posted by Hintalo February 14, 2022
Hi Shlomi,

First I say thank you for your great NGrid library.
As I tried to implement a small demo-app with Infinite-scrolling, the TS compiler reported following error:

Error in template:

error TS2322: Type 'PblInfiniteScrollDataSource<Person, Person[]>' is not assignable to type 'PblDataSource<Person, any, PblDataSourceTriggerChangedEvent<any>, PblDataSourceAdapter<Person, any, PblDataSourceTriggerChangedEvent<any>>> | DataSourceOf<...>'.

image

Then I tried to simplify my component but the error has not disappeared.
I have taken the demo-app from your Infinite-Scroll documentation, as a starting point. My demo-component is even shorter, it is very minimalistic, but the error is still there:

import {Observable, Subscriber} from 'rxjs';
import { ChangeDetectionStrategy, Component, ViewEncapsulation } from '@angular/core';
import { columnFactory } from '@pebula/ngrid';
import {createInfiniteScrollDS, PblInfiniteScrollTriggerChangedEvent} from '@pebula/ngrid/infinite-scroll';
import {
  PblInfiniteScrollDataSource
} from "@pebula/ngrid/infinite-scroll/lib/infinite-scroll-data-source/infinite-scroll-datasource";

export interface Person {
  id: number;
  name: string;
  gender: string;
  birthdate: number;
}

@Component({
  selector: 'infinite-scroll-component',
  templateUrl: './infinite-scroll.component.html',
  styleUrls: [],
  encapsulation: ViewEncapsulation.None,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class InfiniteScrollComponent {

  public columns = columnFactory()
    .table(
      { prop: 'id', width: '100px', pIndex: true },
      { prop: 'name', width: '100px' },
      { prop: 'gender', width: '50px' },
      { prop: 'birthdate', width: '25%' },
    )
    .build();

  public ds: PblInfiniteScrollDataSource<Person, Person[]> = createInfiniteScrollDS<Person>()
    .withInfiniteScrollOptions({
      blockSize: 100,
      initialVirtualSize: 100,
    })
    .withCacheOptions('sequenceBlocks')
    .onTrigger((event: PblInfiniteScrollTriggerChangedEvent<Person[]>) => {
      if (event.isInitial) {
        this.ds.setCacheSize(200 * 4);
        return [] as Person[];
      } else {
        console.log(event.fromRow, event.toRow);
        return [] as Person[];
      }
    })
    .create();

  constructor() { }
}

The template code is also a copy of the infinite-scroll example:

<pbl-ngrid [dataSource]="ds" [columns]="columns">
  <!--mat-progress-bar *ngIf="ds.adapter.virtualRowsLoading | async" mode="indeterminate"></mat-progress-bar-->
</pbl-ngrid>

Could you please give some hint, was could be wrong with this component.
I'm using NGrid 4.0.0 with Angular 12.2.16 and Typescript 4.3.5 in my project (which was created using Angualr CLI).

Thank you,
Peter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant