Comments (4)
@dhilt not a bug, my mistake... sorry!
should return empty stream instead of empty array:
return (start <= end) ? this.fetchItems(start, count) : Observable.of([]);
Thanks for the help, much appreciated! 👍
from ngx-ui-scroll.
@dabcat The returning array should be an observable too, so you can't just return []
from the Datasource.get
, you may wrap it with Observable
, something like
return new Observable(subscriber => subscriber.next([]));
Also, I think, a following workaround should work:
get: (index, count, cb) => {
return (Math.max(1, index) <= index + count - 1) ? this.fetchItems(start, count) : cb([]);
}
The uiScroll
checks Datasource.get
each time it is called. So it could be Observable-based at one iteration and callback-based at another one. But I would recommend to use single signature, just for a consistency.
Also, you may move all negative logic from Client to Server. Server may return an empty array.
from ngx-ui-scroll.
@dabcat Thanks for the issue! Preventing negative indexes is the Datasource
responsibility. In terms of the uiScroll
, you want the Datasource
to be limited on backward direction. So you need to adjust your Datasource
implementation to return empty array when the index becomes negative. But you need to be careful for not to cut edge positive items. Let me explain a bit.
When a bufferSize
(default is 5 currently) of items is requested let us say starting from index -4, you indeed need to return an empty array (assuming that you want to index your dataset starting with index 1). For starting index -3 the return array should consist of single item # 1 in your dataset (items -3, -2, -1 and 0 are ignored). For -7 it should be array of 2 items # 1 and # 2 and so forth.
In the Different item heights demo we have an example of limited callback-based Datasource
starting from index 1. If I remove forward direction limitation, I would get something like
datasource: IDatasource = {
get: (index, count, success) => {
const data = [];
const start = Math.max(1, index); // so # 1 is the minimal possible index value
const end = index + count - 1;
if (start <= end) {
for (let i = start; i <= end; i++) {
data.push({ id: i, text: 'item #' + i, height: 20 + i });
}
}
success(data);
}
}
The uiScroll
stops scrolling (by given direction) when the result of Datasource.get
is an empty array or an array of length less than bufferSize
!
from ngx-ui-scroll.
@dhilt Thanks for prompt reply!
Seems like there is a bug when using Observables instead of promises, it wont trigger datasource again when reaching end of list:
public datasource: Datasource = {
get: (index, count) => {
const start = Math.max(1, index);
const end = index + count - 1;
return (start <= end) ? this.fetchItems(start, count) : [];
},
settings: {
bufferSize: 100
}
};
fetchItems(buffer, count): Observable<any> {
return this.http.post(this.url, {
filters: [],
index: buffer,
quantity: count
}).pipe(
filter((res: any) => res.data.list.length > 0),
map((res: any) => res.data.list)
)
}
So to clarify, scrolling down should load new results but scrolling up shouldn't once index is less or equal to zero.
from ngx-ui-scroll.
Related Issues (20)
- What is the best practice to update an item within the list without flashing? HOT 2
- Smoothscrolling HOT 6
- Mouse wheel scrolling gets stuck on loading after updating Chrome (v102) HOT 2
- Item separation HOT 3
- Scroll position jumps/changes when new items are loaded in viewport HOT 2
- Data loading is abnormal when scrolling up HOT 6
- Nested cdkVirtualFor in cdk-virtual-scroll-viewport HOT 1
- Sluggish on iOS HOT 3
- Observable dataSource change (emission) does not update uiScroll list HOT 4
- remove\update\prepend does not work properly HOT 2
- Scrolling on item click when it's not fully visible in list HOT 2
- TypeError: Cannot read properties of undefined (reading 'log') HOT 5
- Angular 16 compatibility ? HOT 1
- Issue: adaptor.reload(reloadIndex) not functioning correctly on iOS HOT 11
- Object reference after appending HOT 2
- Is it possible to implement nested uiScroll? HOT 4
- Multiple scroll components with windowViewport HOT 6
- Custom Routines
- Pause/resume methods
- Viewport loads all items when positioned at top HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ngx-ui-scroll.