GithubHelp home page GithubHelp logo

diprokon / ng-table-virtual-scroll Goto Github PK

View Code? Open in Web Editor NEW
133.0 133.0 41.0 3.06 MB

Virtual Scroll for Angular Material Table

Home Page: https://diprokon.github.io/ng-table-virtual-scroll

License: MIT License

JavaScript 0.14% TypeScript 73.35% HTML 19.04% CSS 1.05% SCSS 6.42%

ng-table-virtual-scroll's People

Contributors

dependabot[bot] avatar diprokon avatar iuliancmarcu avatar nightapes avatar nthornton2010 avatar proggler23 avatar raphael-inglin-ergon avatar zauni avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ng-table-virtual-scroll's Issues

Observable DataSource

Hi,

I have question how use your directive with Observable ??

I know when you want to use Observable data source you have to define your own class like below:

export class SampleDataSource extends DataSource<T> {	
  constructor() {	
    super();	
  }	

  connect(collectionViewer: CollectionViewer): Observable<T[]> {	
    return Observable<T[]>();	
  }	

  disconnect(collectionViewer: CollectionViewer): void {}	
}

How to apply in your directive ??
Does your directive support async pipe ??

Maybe I have missed something but if you could give me example I will appreciate it :)

Scrolling with Sticky Header

When scrolling a table with complex rows having a sticky header, the header scrolls with the content. If i set the bufferMultiplier to something very high then this does not happen. Can you suggest how to go about this issue please. thanks a lot

Laggy loading

If there are a lot of elements and the table is complex one - everything is loading even slower than without virtual scroll.

"@angular/cdk": "^7.2.0",
"@angular/material": "^7.2.0",
"ng-table-virtual-scroll": "^1.3.1",

Browsers: the most up-to-date Chrome and Mozila

scrollbar jerks up and down

When dragging the scrollbar from the top down, at first the table rows scroll as expected, but when I reach about 70-80% down the scrollbar starts jerking up and down.
Note: the table has variable row heights, perhaps that is what causes the jerk?
See attached recording.

scrpll3.mov.zip

Column width changes on scroll

Hello!

It's distracting when column width or position changes when scrolling, the items are no longer aligned vertically. What I mean is that tables are good for aligning items horizontally and vertically, it's visually jarring to have columns jiggling around like that.

A very good example of this is the Table with filter, sort and selection example:
https://diprokon.github.io/ng-table-virtual-scroll/#/examples
I have the same problem, albeit less extreme because text length does not vary that much I think.

table jerks up and down

when my chart slides a few times and then release the mouse, the chart content will fluctuate up and down. Similar to [https://github.com//issues/30]. But setting'tvsItemSize' with no value still cannot solve this problem for me.

My code:
<cdk-virtual-scroll-viewport tvsItemSize [headerHeight]="64" [bufferMultiplier]="15" [ngStyle]="{'height': tableHeight, 'width': '100%'}"> <table mat-table [dataSource]="tableRows" matSort matSortActive="{{matSortActive}}" matSortDirection="{{matSortDirection}}" matSortDisableClear (matSortChange)="sortData($event)" matSortStart="desc" [multiTemplateDataRows]="true"> ... ... </table> </cdk-virtual-scroll-viewport>

And a blank area will appear on the chart when you swipe quickly.

My data is 1,800 pieces of more complex data. Will this have any effect?

get and set declared in typescript interface dataLength property

ERROR in node_modules/ng-table-virtual-scroll/lib/fixed-size-table-virtual-scroll-strategy.d.ts(20,9): error TS1086: An accessor cannot be declared in an ambient context.
node_modules/ng-table-virtual-scroll/lib/fixed-size-table-virtual-scroll-strategy.d.ts(21,9): error TS1086: An accessor cannot be declared in an ambient context.

Failed in runtime.
"@angular/cli": "~7.1.4",
"typescript": "^3.1.6",

I tried to update to tsc 3.8.3 but my angular cli return an error
ERROR in The Angular Compiler requires TypeScript >=3.1.1 and <3.2.0 but 3.8.3 was found instead.

I can't upgrade at this moment.

Add support also to CDK table

Currently the library support only Mat table. Please add support to CDK table.

Note:

  1. ContentChild of mat table in table-item-size.directive.ts, link.
  2. css selectors in table-item-size.directive.ts, link.

How to set templateCacheSize?

I would like to change the templateCacheSize which is accessible on the *cdkVirtualFor property. Is there a way to set this up?

Couldn't initialise the table with data

Hi all,

I was trying to figure a way to implement virtual scroll and came here to use it.

Installed the plugin from Npm and tried fulfilling my requirement.

But at the initially stage it self, i couldn't assign my data to dataSource as show in the example.

FYI, here I'm attaching my code snippets screenshots as well. Any suggestions will be appreciated.

Screenshot 2021-01-15 at 7 03 35 PM

Screenshot 2021-01-15 at 7 03 44 PM

Screenshot 2021-01-15 at 7 06 44 PM

Fast scrolling

When scrolling fast a table (200-300 rows), the sticky header scrolls with the content and in some cases the table disappears for 1-2 seconds.
I'm using directives approach instead of components.

Any advice on this ?

Virtual Scrolling on both axis?

Hi,

Just for information is the current library compatible with a virtual scrolling horizontal & vertical at the same time?

Thanks in advance,
B R

Scroll issue with solution

Using directive with datasource, virtual scroll works great. But experiencing issue with keyboard navigation (Arrow Up/Arrow Down) and scrolling of the contents.
We have mat table with sticky headers.
To reproduce, first scroll down with arrow keys so first 5 rows would disappear from the viewport, then start scrolling up. Once top visible row reached, contents is not scrolled, but almost feels like it counts header row as a part of the visible scroll area. It feels that scroll is one row behind because of counting of the header row as a part of visible scroll.

Custom sorting and filtering method

Custom sorting and filtering methods are not working with this project

@ViewChild(MatSort, {}) sort: MatSort;

this.dataSource.sortingDataAccessor = ...
this.dataSource.filterPredicate = ...

then
this.dataSource.sort = this.sort;
this.dataSource.filter = filterValue;

Issue with filtered data

When data is filtered the scrolling behaviour is not changed and still tries to scroll through all data records.

For example: Data has 100 records. Filtered Data has only 10 records. It is still possible to scroll further than the availabla 10 records, which also breaks the sticky header.

I think filtereddata should be used instead of data, since it is also that what is displayed.

Rows not shown if the table is initially hidden

Hello,

When the table is initally hidden with CSS (display:none) and displayed programmaticaly, the rows are not shown unless you force the re-rendering (by changing windows size for example).

See the following Stackblitz for an example:
https://stackblitz.com/edit/angular-rdotb9?file=src/app/base-example.component.ts

If you change value of hideCdkVS to false, it will works fine but if it's hidden by default (hideCdkVS = true;) and then you click on the show button, the table will be rendered but not the rows. If you then change the size of the window, the rows will be rendered.

Issue when table has borders;

Hi!

Try to set the border & border-radius on the header & for cells of the table.
Then, if you scroll, you will notice that the border from the cell is visible and overlapping with the header, which should not be the case (basically, it forces you to avoid using border-radius on the header).
Please, have a look at the screenshot as well. The green areas are the ones from cells that overlap at the corners of rounded header.

Best, Server.

Screenshot 2020-01-16 at 15 17 57

Render table when lost focus

Hi,

I created exmaple about a behaviour current issue whether even maybe a bug:

Here is example to have a look: Example

Step replication:

  1. Click 'Primary Button'
  2. Output Result (Console):
Service Data Source: 0
Service Data Source: 1000
  1. Click on search input and populate a word 'Wood'
  2. Output Result:
########### Search Start ##############
Data Table Source:
1000
Filter Table Data:
2
[Object, Object]
########### Search End ##############
Service Data Source: 2

Screenshot 2020-07-25 at 11 09 02

  1. Remove couple of letters to make a result: 'Wo'
  2. Output Result:
########### Search Start ##############
Data Table Source:
1000
Filter Table Data:
7
[Object, Object, Object, Object, Object, Object, Object]
########### Search End ##############
Service Data Source: 7

Screenshot 2020-07-25 at 11 13 33

MAGIC MOMENT: LOST FOCUS FROM THE INPUT AND THEN:

Screenshot 2020-07-25 at 11 15 20

BUT !!!

remove and clear a input and you have an old results, i expect whole list..
Screenshot 2020-07-25 at 11 16 52

QUESTION: What I'm doing wrong whether you have a bug and you don't refresh the list or call a proper event that tells the list has been updated and you have to refresh and render again

PLEASE HELPPPPPP :D @diprokon

I don't see tbody rendering any rows. I copied code from live demo basic-example.

Installed using the command npm install -save ng-table-virtual-scroll.

My tbody does not have any rows displayed. I copied the code from live demo basic one and the data is also available from util.ts file.

Does it need a specific version of angular cdk and material, etc?

Also i do not see the below div after rendering:

My package.json shows the following:
"@angular/cdk": "^7.2.1",
"@angular/material": "^7.2.1",
"ng-table-virtual-scroll": "^1.3.1",

Ivy support

When I launch the application with Angular 13 I get

โ ™ Generating browser application bundles (phase: setup)...Processing legacy "View Engine" libraries:
- ng-table-virtual-scroll [es2015/esm2015] (git://github.com/diprokon/ng-table-virtual-scroll.git)
Encourage the library authors to publish an Ivy distribution.

Any plans to fix this?

Material Table not found for new Angular Material Version

I am using Material V 9.0.0 and it seems that the import of MatTableDataSource is failed. From the material docs:

From changelog:

material

Breaking changes:

Components can no longer be imported through "@angular/material". Use the individual secondary entry-points, such as @angular/material/button.

It would be nice if the dependencies get updated for the new version of material.

Need VirtualScrollStrategy's for non-fixed rows

My use case involves variable height rows.
I noticed the code is based on a FixedSizeTableVirtualScrollStrategy.
I'd like to see additional scrolling strategies implemented (or at least provide a way for developers to override the default?)

Thanks

Custom inputs tvsItemSize and headerHeight ignored

In my tsconfig.json I've enabled

"angularCompilerOptions": {
    "strictInjectionParameters": true,
    "strictInputAccessModifiers": true,
    "strictTemplates": true
  }

This causes compiler errors for

<cdk-virtual-scroll-viewport class="scroll-viewport" tvsItemSize="28" headerHeight="32">

I get

error TS2322: Type 'string' is not assignable to type 'number'.

for both inputs, tvsItemSize and headerHeight. So, I changed the syntax to

<cdk-virtual-scroll-viewport class="scroll-viewport" [tvsItemSize]="28" [headerHeight]="32">

then the compiler is happy, but my values are ignored, I always get the table with defaults values (48 for tvsItemSize and 56 for headerHeight).

Multiple sticky header not working.

When we attach multiple sticky header in a table. Only latest header row works fine. I inspected a bit on the rendered html and found that as all the header rows are given a fixed Html "top" value. The first header row gets hidden under the second header row.

not an issue - a suggestion :)

I needed to use async data for the table and couldn't get the package to work properly so I took it into the project and basically had to change just 1 thing that made it work great

on table-item-size.directive.ts :
instead of

  @ContentChild(MatTable, { static: **true** })
  table: MatTable<any>;
  @ContentChild(MatTable, { static: **false** })
  table: MatTable<any>;

Checkbox toggling inconsistent in example

I'm amazed with your directive! It's a bummer the Angular team is dragging their feet with angular/components#10122.

In the example for "Table with filter, sort and selection" in the live demo, the checkboxes function very inconsistently. For example, try checking each row, one at time and occasionally toggling the header checkbox.

I'm not sure whether this broken functionality is reflective of the virtual-scroll implementation or just a bug with how checkbox states are managed (hopefully the latter, as I could really use the checkbox functionality!).

This was noticed in Chrome 78.0.3904.97.

Angular Material Tab lost data

๐Ÿž BUG REPORT

Description
When using angular material tab (8.2.3) and then you are trying scroll on down then data is gone for some reason.. You must refresh page to get table with data again..

๐Ÿ”ฌ Minimal Reproduction
https://stackblitz.com/edit/angular-material-tab-example-uca6w3

๐Ÿ”ฅ Exception or Error
None

๐ŸŒ Your Environment
Screenshot 2020-02-13 at 23 53 08

Any ideas ??

ps. Awesome solution. I am glad and happy you did it !! Many thanks ๐Ÿ—ก

Triggering scroll by code does not work.

I want to trigger the scroll of the CdkVirtualScrollViewport by calling scrollToIndex.

Expected behaviour:

  • The virtual scroll viewport scrolls to the passed index parameter.

Actually nothing happens.

Worked around the issue by using the scrollBy function of the viewport nativeElement. But still, the issue remains.

Multiple Sticky Header Rows

Hey there,

when using multiple sticky header rows the first row gets hidden under the second row. Seems like a duplicate of Issue #21.
Im on version 1.3.4 with @angular/cdk 10.2.7, so the fix mentioned in #21 should already be applied. But it still does not work properly.

Any advice on this?

Example can be found here: StackBlitz

Sticky footer not working

Hi, I have a table with sticky header & footer.
The header is working fine, but the footer stops sticking after a couple of scrolls

Issue with dynamic spanrow

Hello,
great work, i really appreciate this lib!
i'm just facing some issuee when using in combo with dynamic spanrow
When using a code like this:

<td
              mat-cell
              *matCellDef="let element; let i = index"
              [style.padding-left]="'5px'"
              [style.padding-right]="'5px'"
              [style.display]="getRowSpan(col, i) ? '' : 'none'"
              [attr.rowspan]="getRowSpan(col, i)"
            >
              <div [innerHTML]="element[col]"></div>
            </td>

spanRow(key: any, accessor: any) {
    for (let i = 0; i < this.DATA.length; ) {
      const currentValue = accessor(this.DATA[i]);
      let count = 1;

      for (let j = i + 1; j < this.DATA.length; j++) {
        if (currentValue !== accessor(this.DATA[j])) {
          break;
        }

        count++;
      }

      if (!this.spans[i]) {
        this.spans[i] = {};
      }

      this.spans[i][key] = count;
      i += count;
    }
  }

  getRowSpan(col: string | number, index: string | number) {
    return this.spans[index] && this.spans[index][col];
  }

The result in some columns is broken:
Screenshot 2020-01-25 at 09 27 17
(Buon 1980 is not spanned like the others, when not using this lib is working right)

Thanks again!

adding new TableVirtualScrollDataSource not working

Hi,

the docs say we must do
vDataSource = new TableVirtualScrollDataSource(ELEMENT_DATA);
but for me it doesn't work

What works is just sending the data directly. So if you replace [dataSource]="vDataSource" with [dataSource]="dataSource" the cells are displayed but I don't know if the virtual scroll is working as expected

Maybe the docs need to be updated?

Thank you

Example:
https://stackblitz.com/edit/angular-cpxqbh?file=src/app/table-basic-example.html

Update:
Copy-pasting one of the examples in stackblitz has the same behavior, no cells if new TableVirtualScrollDataSource is used
https://stackblitz.com/edit/angular-cpxqbh-nembpx?file=src%2Fapp%2Ftable-basic-example.ts

If Table is rendered but not visible then the grid wont scale correctly

In a Component have 3 tabs.
In each tab I have a virtual Scroll table and are loaded when the component loads (ngOnInit).

As just 1 table is visible at a time, the grids that are hidden appear collapsed (only showing header and footer) when changing to it's tab. And only show themselves when resizing the window.

Observe changes in dataSource input of mat-table component

Often there is a use case for when the dataSource input parameter is not a static value. Currently, if we pass a new object to dataSource after initialization of the view, then the tvsItemSize directive fails to display any table rows because it was connected to the previous instance (see ngAfterViewInit method in TableItemSizeDirective). Any new instances of dataSource will not be connected to since we do not observe changes.

Proposal: use MutationObserver web api as seen here: https://nitayneeman.com/posts/listening-to-dom-changes-using-mutationobserver-in-angular/

The tvsItemSize directive should do something like the following:


ngAfterViewInit() {
   const element = this.table;

   const changes = new MutationObserver((mutations: MutationRecord[]) => {
      mutations.forEach((mutation: MutationRecord) => this.connectToDataSource(mutation)
   });

   changes.observe(element, {
       attributes: true,
    });

   this.scrollStrategy.stickyChange
      .pipe(
        filter(() => this.isStickyEnabled()),
        takeWhile(this.isAlive())
      )
      .subscribe((stickyOffset) => {
        this.setSticky(stickyOffset);
      });
}

private connectToDataSource(mutation: MutationRecord) {
    if (this.table.dataSource instanceof TableVirtualScrollDataSource) {
      const dataSource = this.table.dataSource;
      this.scrollStrategy.renderedRangeStream
        .pipe(
          takeUntil(newDataSource), // need to unsubscribe when new datasource comes in
          takeWhile(this.isAlive())
        )
        .subscribe(range => {
          this.zone.run(() => {
            dataSource.renderedRangeStream.next(range);
          });
        });
      dataSource.connect()
        .pipe(
          map(() => dataSource.data.length),
          distinctUntilChanged(),
          takeUntil(newDataSource), // need to unsubscribe when new datasource comes in
          takeWhile(this.isAlive())
        )
        .subscribe((length) => {
          this.scrollStrategy.dataLength = length;
        });
    } else {
      throw new Error('[tvsItemSize] requires TableVirtualScrollDataSource be set as [dataSource] of [mat-table]');
    }
}

Angular: strictTemplates cause problems

Angular10:
If I have something like

<cdk-virtual-scroll-viewport tvsItemSize [ngStyle]=...

the Angular compiler complains

     ....   error TS2322: Type 'string' is not assignable to type 'number'.
  4   <cdk-virtual-scroll-viewport tvsItemSize [ngStyle]="{'height': 'calc(
                                   ~~~~~~~~~~~

is there a way to fix this issue? Or better: To assign the values properly?

Scroll with sticky headers

Sticky header dissappearing while you scroll items. This issue is reproducing while you scroll items on your demo page with sticky headers! Tested with Chrome Mobile browser. Will you fix it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.