- Home
- Forum
- Angular - EJ 2
- Lazy Loading and LoadOnDemand with ChatUI
Lazy Loading and LoadOnDemand with ChatUI
Hi Syncfusion team,
How can I implement lazy loading with LoadOnDemand with ChatUI component?
As I know, LoadOnDemand is used to improve the UI (without loading every messages on the UI DOM), but all the messages still need to load on memory.
Is there a way to detect the scroll position, or the user has scroll to the top, so that I can trigger and fetch more messages and update them onto the ChatUI component?
Hi Tuan,
Sorry for the delay in getting back to you.
In the ChatUI component, you can use the loadOnDemand property to dynamically load messages when the scrollbar reaches the top of the initially loaded messages. This feature enhances performance and reduces load times, by dynamically loading the messages.
We have already considered an enhancement feature to “Provide an event to detect scrollbar top position in the Chat UI” from our end. This would allow you to programmatically update messages when scrollbar hits the top. Generally, we plan and implement features based on their rank, customer request count, and wishlist volume. We will implement and include this feature in any one of our upcoming releases.
You can track the status of this feature request through the following feedback link:
https://www.syncfusion.com/feedback/69078
Please get back to us if you need any further assistance.
Regards,
Vigneshwaran
HI Vigneshwaran Govindharajan,
This feature is extremely important for our team. We are actively building a production system that relies on the ChatUI component, and the ability to detect the scrollbar position (especially when it reaches the top) is critical for implementing proper lazy loading and infinite scroll.
Without this event, we’re currently unable to efficiently fetch and append older messages without performance drawbacks, which makes large conversations difficult to handle at scale.
Could you please share an estimated timeline or release version when this feature is expected to be available? This is a high-priority requirement for us.
Thank you for considering this.
-Vlad
Tuan,
We’re pleased to inform you that support for loading dynamic messages on demand, allowing users to fetch older messages when scrolling to the top of the chat window, will be included in the upcoming Volume 3 Service Pack Release 2, scheduled for the mid of November 2025.
As part of this enhancement, we’ve introduced a new property called bufferMessageCount, which lets you specify the number of additional messages to preload when loading older messages.
Could you please confirm if this enhancement meets your requirements? If you have any additional expectations or suggestions.
Please let us know if you need further assistance.
Regards,
Vigneshwaran G
HI Vigneshwaran Govindharajan,
Thanks for the update — that’s great news! The addition of bufferMessageCount and the support for loading dynamic messages on demand sounds very promising.
Could you please share a bit more detail on what’s included in this enhancement? Specifically:
Will there be an event or callback triggered when the user scrolls to the top of the chat window, so we can execute our own API call to fetch older messages?
How does
bufferMessageCountinteract with the message loading process — for example, does it control prefetching on scroll or batch loading behavior?
Having an event we can hook into (such as onScrollTopReached or similar) would be essential for our integration since we need to handle the API call for fetching older messages dynamically.
Looking forward to your clarification and any examples or documentation you can share.
Best regards,
Vlad
Vlad,
Sorry for the delayed response,
As mentioned earlier the bufferMessageCount only specifies the number of extra messages to preload when loading older messages in the ChatUI based on the user needs.
However, we suspect your requirement might be kind of lazy loading fetching the messages dynamically and adding in the chat. However, we have prepared a sample which meets your requirements, by adding the container scroll event to load messages dynamically when it hits the scroll top. The following are handled in the shared sample.
- Using the chat UI component created event bound the scroll event.
- Helper function where the new messages are to be loaded when the scroll hits the top.
- Loading the dynamic messages using the messages property in the chat UI component.
App.component.ts
|
public onCreated(): void { var wrapperElement = this.chatUIComponent.element.getElementsByClassName('e-message-wrapper')[0]; wrapperElement.addEventListener('scroll', () => { if (wrapperElement.scrollTop === 0) { this.onScrollTopHit(); } }); } |
App.component.ts
|
private onScrollTopHit(): void { const newMessages: MessageModel[] = []; const existingCount = this.chatMessages?.length ?? 0;
for (let i = 1; i <= 10; i++) { const isEven = i % 2 === 0; newMessages.push({ text: isEven ? `Scroll Top new Message ${i + existingCount} from Michale` : `Scroll Top new Message ${i + existingCount} from Albert`, author: isEven ? this.michaleUserModel : this.currentUserModel }); } this.chatMessages = [...newMessages, ...(this.chatMessages ?? [])]; this.chatUIComponent.messages = this.chatMessages; this.chatUIComponent.dataBind(); …. } |
Output:
Demo: Link
Can you please check the shared demo and let us know if it meets your requirements ?
Regards,
Indrajith
- 5 Replies
- 4 Participants
-
TN Tuan Ngueyn
- Jul 22, 2025 05:24 PM UTC
- Oct 31, 2025 07:28 PM UTC