ngx-ui-scroll icon indicating copy to clipboard operation
ngx-ui-scroll copied to clipboard

Allow to pass all the data at a time (as an alternative to Datasource.get)

Open philly-vanilly opened this issue 5 years ago • 4 comments

If I understand correctly, there is no way to pass a whole array of items (handled in the redux store or some other external model) to the adapter/datasource-get and make it accept all of them. Instead you have to manually synchronize all the changes that happen at network-layer with subscibe/update methods. For enterprise applications that have layered architecture with separation of business and UI, this means a lot of boilerplate code that can and will result in bugs.

It would be nice if you could just pass an array or observable of an array to the ngx-ui-scroll directive (same way as angular material CDK or Ionic) and make it handle the rest.

philly-vanilly avatar Apr 09 '19 05:04 philly-vanilly

@philly-vanilly Thanks for the issue! Looking through Material CDK Virtual scrolling documentation, I would say that current ngx-ui-scroll approach correlates with "Virtual scroll with a custom data source" ("Specifying data") Material approach. They also suggest to implement MyDataSource and provide paging data flow manually (example).

I'm not going to explain why manual datasource approach is important or could be useful, but I would agree that it is a good idea to have an additional API allowing to pass all the data array at a time. Also, I believe Redux isn't involved here. So I'm going to change the issue title and add "enhancement" label.

dhilt avatar Apr 09 '19 11:04 dhilt

This issue has been automatically marked as stale because it has not had recent activity. It will be closed within seven days if no further activity occurs. If it needs to remain open, add the "permanent" label.

stale[bot] avatar Jan 15 '20 15:01 stale[bot]

Hi @dhilt , Priority wise, is this something likely to be brought in soon? are there any workarounds?

Thanks for keeping up one of most well documented and maintained repos btw. Very appreciated

HadiAyoub avatar Jan 19 '21 13:01 HadiAyoub

@HadiAyoub I'm keeping this issue in mind, though there are not so many requests on it. Right now all my time is being spent on vscroll finalization, it will be an external framework-free core for ngx-ui-scroll, and this enhancement will go there after v1 is released.

While there is no this feature implemented, you may use the following approach:

datasource = new Datasource({
  get: (start, count, success) => {
    const end = Math.min(start + count - 1, this.data.length - 1);
    success(start <= end ? this.data.slice(start, end + 1) : []);
  }
})

Here this.data is your dataset fixed on the Component's level.

dhilt avatar Jan 19 '21 13:01 dhilt