-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
How to replace all visible and virtual items following a given one (was: White space at the bottom) #234
Comments
@jyothi530 1. Sure, use viewportElement setting. It is marked as experimental due to no restrictions on the lib's side, while essentially there are some: viewport element must be a parent of a scroller element. But it is being used and will be fully backward-compatible at least until ngx-ui-scroll v2, and most likely after v2 (by the way, no plans for v2 for now).
async doInsert (params) {
const { adapter } = this.myDatasource;
await adapter.relax();
await adapter.insert(params);
await adapter.clip();
} I'm glad to hear the lib is useful and happy to assist! |
@dhilt Thanks for the quick reply. I am using exactly like the above code snippet you mentioned. Will revert with a stackblitz sample. |
Hi @dhilt, Here is the stackblitz url (https://stackblitz.com/edit/angular-ivy-qm8h6g). I created an array with 100 elements. I am inserting a set of items after index 6. To perform this operation I am removing all the items after index 6. Adding the new items along with items that are removed after index 6 with
Psuedo code for above operation
Without |
@jyothi530 Great! The demo is very helpful. I see two major problems with the approach you implemented there. First, is on the App side. All changes made over the Scroller must be synced with the Datasource. We have 2 data levels: Scroller's Buffer (including virtual data) and App's Datasource (which provides data to the Scroller on demand, per scroll events). If you want to make any change in the Scroller's data, you need also to update the App Datasource. That's why you see duplications. This problem needs to be addressed anyway, because this is the main point of consistency. Second, is on the Scroller's end. The remove process (triggering by Adapter.remove) performs a full cycle of the UIScroll Workflow: cut the required items off and ask for new items to fill the viewport. These new items are being taken via Datasource and are being rendered before you call Adapter.insert. I think, this problem can be solved, but we need to discuss it. For example, you may try to change Datasource in the same manner as you make your updates via Adapter: cut off DS items, call Adapter remove, insert DS items, call DS insert. I'm not sure, but this might require also managing min/max indexes (via Adapter.fix) because the internal request to the data after Adapter.remove will update them in accordance with DS update made right before Adapter.remove. Another option is to deal with visible items only. You know the pack you want to update, so you may split it. Say, there was 1...100 items initially, 1..6 visible items should remain pristine, 6..20 visible items needs to be changed, and there will be 20..90 virtual items because 10 virtual items should gone. First, you need update the Datasource, for DS.get should return index-count portion properly after the update; it should manage [1..90] items. Then you make 2 steps: update 6..20 items via Adapter (since ngx-ui-scroll v1.11.0-rc.1 you may use Adapter.replace for this purpose, it can replace items in the Scroller's Buffer in a single run) and shift maxIndex via Post another version of demo if any questions or concerns, I will take a look. |
@jyothi530 This depends on the App requirements. There are some examples, like this one, but the main idea is that the |
@jyothi530 Well, I spent some time to accomplish virtual replacement demo based on your case: https://stackblitz.com/edit/ngx-ui-scroll-virual-replacement It implements the last option from my previous comment with no extra render. Conditions: the dataset boundaries are known, indexes start from 0. Current min/max Buffer indexes are calculated via Adapter.fix-updater API, which does not seem intuitive, so I created separate issue #236 for this. I hope the concept does make sense, and you can apply it in your environment. Indexes consistency is the first point you need to care of, and you have to maintain it across the Datasource-Buffer updates of any complexity. Virtual replacement is very interesting use case. Currently the ngx-ui-scroll has limited API which can't fulfil this task in short and strict manner. But it is possible, and my demo shows it. |
@dhilt Thank you for the demo app. I actually applied the first option in your previous comment in my application. It worked the way I expected. There was one scenario when if I perform the operations (remove then insert then clip) repeatedly say more than 100 times I got "Maximum call stack size reached". I tried to replicate the issue in the demo app to show you but was unsuccessful (Might be since demo app is lightweight and my actual application will be having other events that will be firing). |
I think the title of the issue is not appropriate with the discussion we are having in this thread. I came up with that title when I use the viewport element that is not immediate parent of uiScroll. But figured out in settings of Datasource I can pass a function that determines the viewPortEle. |
@jyothi530 👍 By the way ngx-ui-scroll v1.11.0 is almost done, it will be released during the next week. The rc versions appeared due to the request for one-to-one replacement feature, someone couldn't wait for many-to-many is done. |
Hi @dhilt
I wanted to use ngx-ui-scroll. My requirement is having items with variable height. Your library is a good fit for my requirement but have some issues that I wanted to solve and need your suggestions.
On the settings object I see the viewPortElement property exposed which can take either HTMLElement or Function. Is it suggested to use that approach. Using that I am able to get rid of whitespace in the bottom and also no double scroll bar
remove()
andinsert()
. This works fine but I observed after usingremove()
andinsert()
in the DOM the items are not virtualized. I have to callclip()
but that is causing inconsistent behavior.(Eg: You can relate the requirement to a scenario where there will be a certain set of questions. Answering a question can show/hide other questions)
Can you please suggest me the best solution.
Thanks for the wonderful library.
The text was updated successfully, but these errors were encountered: