Lazy load from API until the screen is full

Hi

Context:

  • A SfDataGrid component uses loadMoreViewBuilder to do  lazy load.
  • However if the screen has a big height, the first load do not fill the screen.

How to implement a logic that would does if the screen is not full continue tu lazy load ?


I tried some scroll bar detection with the following code to detect if the screen is  filled o
maxScrolled = _scrollController.position.pixels == _scrollController.position.maxScrollExtent

But in the loadMoreViewBuilder logic when the data source is filled with new data, the UI, and so the scroll status is not yet modified.


Would you please advice on how to achieve it ?




1 Reply

AP Abinesh Palanisamy Syncfusion Team September 3, 2024 05:31 AM UTC

Hi arthox,


Query

Solution 1

Solution 2

How to implement a logic that would does if the screen is not full continue the lazy load ?

We would like to inform you that the LoadMoreViewBuilder will only be called if the DataGrid is vertically scrollable.  Therefore, you should ensure that the number of rows exceeds the view size. Additionally, the "Load More" view will appear when the vertical scroll reaches its maximum offset.

 

If you want to load more rows when the number of DataGrid rows is fewer than the view size, you can use a footer widget. This widget adds an extra row at the bottom, below the last available row. By using this footer widget, you can add more rows by tapping the button, thus achieving your desired functionality.

 

Implement a function to estimate the height of the DataGrid based on the number of rows and their approximate height. Check if the height of the DataGrid is less than the screen height, and trigger the loading of more data if necessary. The _loadMoreIfNotFull function calculates whether the DataGrid is full and triggers the loading of additional data if it is not.


We have included two samples for your reference. Please review them for more details and adapt them to suit your specific requirements.


Regards,

Abinesh P


Attachment: SfDataGrid_solutions_11aba06e.zip

Loader.
Up arrow icon