|
1 | 1 | --- |
2 | 2 | layout: post |
3 | 3 | title: Infinite Scrolling in Blazor DataGrid | Syncfusion |
4 | | -description: Checkout and learn here all about Infinite Scrolling in Syncfusion Blazor DataGrid and much more details. |
| 4 | +description: Learn how to implement Infinite Scrolling in Syncfusion Blazor DataGrid and explore more advanced features and customization options. |
5 | 5 | platform: Blazor |
6 | 6 | control: DataGrid |
7 | 7 | documentation: ug |
8 | 8 | --- |
9 | 9 |
|
10 | 10 | # Infinite scroll in Blazor DataGrid |
11 | 11 |
|
12 | | -The infinite scrolling feature in the Syncfusion<sup style="font-size:70%">®</sup> Blazor DataGrid is a powerful tool for seamlessly handling extensive data sets without compromising Grid performance. It operates on a “load-on-demand” concept, ensuring that data is fetched only when needed. In the default infinite scrolling mode, a new block of data is loaded each time the scrollbar reaches the end of the vertical scroller. This approach significantly enhances the user experience when working with large data collections in the Blazor Grid. |
| 12 | +The infinite scrolling feature in the Syncfusion<sup style="font-size:70%">®</sup> Blazor DataGrid provides load-on-demand data retrieval to handle large datasets without degrading performance. In default infinite scrolling, the Grid fetches the next block of data when the vertical scrollbar reaches the end of the scroller, creating a seamless browsing experience across extensive data. |
13 | 13 |
|
14 | | -In this mode, a block of data accumulates every time the scrollbar reaches the end of the scroller. To clarify, in this context, a **block** represents the [PageSize](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridPageSettings.html#Syncfusion_Blazor_Grids_GridPageSettings_PageSize) of the Grid. If the `PageSize` is not explicitly specified, the Grid will automatically calculate it based on the Grid viewport height and row height. |
| 14 | +In this feature, a block is equivalent to the Grid’s [PageSize](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridPageSettings.html#Syncfusion_Blazor_Grids_GridPageSettings_PageSize). If `PageSize` is not set, the Grid calculates it from the viewport height and row height. To enable infinite scrolling, set [EnableInfiniteScrolling](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_EnableInfiniteScrolling) to **true** and define a content [Height](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_Height). |
15 | 15 |
|
16 | | -To enable infinite scrolling, you need to define [EnableInfiniteScrolling](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_EnableInfiniteScrolling) as **true** and set the content height using the [Height](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_Height) property. |
17 | | - |
18 | | -> * In this feature, the Grid will not initiate a new data request when revisiting the same page. |
19 | | -> * The `Height` property must be specified when enabling `EnableInfiniteScrolling`. |
20 | | -
|
21 | | -The following is an example that demonstrates how to enable infinite scroll in the Grid: |
| 16 | +> - With this feature, the Grid does not issue a new data request when revisiting a previously loaded page. |
| 17 | +> - The `Height` property must be specified when `EnableInfiniteScrolling` is enabled (a fixed container height is required). |
22 | 18 |
|
23 | 19 | {% tabs %} |
24 | 20 | {% highlight razor tabtitle="Index.razor" %} |
@@ -86,11 +82,9 @@ public class TaskDetails |
86 | 82 |
|
87 | 83 | ## Number of blocks rendered during initial loading |
88 | 84 |
|
89 | | -The number of blocks to be initially rendered when the Syncfusion<sup style="font-size:70%">®</sup> Blazor DataGrid is loaded. Each block corresponds to a page size of the Grid, resulting in the rendering of a certain number of row elements determined by multiplying the initial block size by the page size. |
| 85 | +At initial load, the Grid renders a specified number of data blocks (pages), which equates to the `InitialBlocks` value multiplied by the page size. |
90 | 86 |
|
91 | | -You can define the initial loading page count by using the [InitialBlocks](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridInfiniteScrollSettings.html) property of the [GridInfiniteScrollSettings](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridInfiniteScrollSettings.html) class. By default, this property loads three pages during the initial rendering. Subsequently, additional data is buffered and loaded based on either the page size or the number of rows rendered within the provided height. |
92 | | - |
93 | | -The following is an example of how you can use the `InitialBlocks` property to set the initial loading pages based on **DropDownList** input: |
| 87 | +Configure this using [InitialBlocks](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridInfiniteScrollSettings.html) on [GridInfiniteScrollSettings](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridInfiniteScrollSettings.html). By default, three pages are rendered initially. Afterwards, additional data is buffered and loaded based on page size or the number of rows that fit within the given height. |
94 | 88 |
|
95 | 89 | {% tabs %} |
96 | 90 | {% highlight razor tabtitle="Index.razor" %} |
@@ -189,13 +183,11 @@ public class TaskDetails |
189 | 183 |
|
190 | 184 | ## Efficient data caching and DOM management in Grid cache mode |
191 | 185 |
|
192 | | -In Syncfusion<sup style="font-size:70%">®</sup> Blazor DataGrid cache mode, cached data blocks are reused when revisiting them, reducing the need for frequent data requests while navigating the same block. This mode also manages DOM row elements based on the [GridInfiniteScrollSettings.MaximumBlocks](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridInfiniteScrollSettings.html#Syncfusion_Blazor_Grids_GridInfiniteScrollSettings_MaximumBlocks) count value. If this limit is exceeded, it removes a block of row elements to create new rows. |
193 | | - |
194 | | -To enable cache mode, define the [EnableCache](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridInfiniteScrollSettings.html#Syncfusion_Blazor_Grids_GridInfiniteScrollSettings_EnableCache) property of [GridInfiniteScrollSettings](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridInfiniteScrollSettings.html) as **true**. |
| 186 | +In Syncfusion<sup style="font-size:70%">®</sup> Blazor DataGrid cache mode, previously loaded blocks are reused when revisited, reducing repeat data requests. The Grid manages the number of rendered DOM row elements using [GridInfiniteScrollSettings.MaximumBlocks](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridInfiniteScrollSettings.html#Syncfusion_Blazor_Grids_GridInfiniteScrollSettings_MaximumBlocks). When this limit is reached, the Grid removes an older block of row elements to render new ones. |
195 | 187 |
|
196 | | -To configure the maximum blocks, set the `MaximumBlocks` count of `GridInfiniteScrollSettings`. By default, this property value is 3. |
| 188 | +Enable cache mode by setting [EnableCache](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridInfiniteScrollSettings.html#Syncfusion_Blazor_Grids_GridInfiniteScrollSettings_EnableCache) to **true** on [GridInfiniteScrollSettings](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridInfiniteScrollSettings.html). |
197 | 189 |
|
198 | | -The following example demonstrates how to enable or disable cache mode in infinite scrolling of the Grid based on the [Toggle Switch Button](https://blazor.syncfusion.com/documentation/toggle-switch-button/getting-started-webapp) [ValueChange](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Buttons.SfSwitch-1.html#Syncfusion_Blazor_Buttons_SfSwitch_1_ValueChange) event: |
| 190 | +Configure the maximum cached blocks with `MaximumBlocks` (**default: 3**). |
199 | 191 |
|
200 | 192 | {% tabs %} |
201 | 193 | {% highlight razor tabtitle="Index.razor" %} |
@@ -276,28 +268,28 @@ public class TaskDetails |
276 | 268 |
|
277 | 269 | ## Limitations |
278 | 270 |
|
279 | | -* Due to the element height limitation in browsers, the maximum number of records loaded by the Grid is limited due to the browser capability. |
280 | | -* It is necessary to set a static height for the component or its parent container when using infinite scrolling. The 100% height will work only if the component height is set to 100%, and its parent container has a static height. |
281 | | -* The combined height of the initially loaded rows must exceed the height of the viewport. |
282 | | -* When infinite scrolling is activated, compatibility for copy-paste and drag-and-drop operations is limited to the data items visible in the current viewport of the Grid. |
283 | | -* Cell selection will not be persisted in cache mode. |
284 | | -* The group records cannot be collapsed in cache mode. |
285 | | -* Lazy load grouping with infinite scrolling does not support cache mode, and the infinite scrolling mode is exclusively applicable to parent-level caption rows in this scenario. |
286 | | -* In normal grouping, infinite scrolling is not supported for child items when performing expand and collapse actions on caption rows. All child items are loaded when the caption rows are expanded or collapsed in Grid. |
287 | | -* The aggregated information and total group items are displayed based on the current view items. To get these information regardless of the view items. |
288 | | -* Programmatic selection using the [SelectRowsAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_SelectRowsAsync_System_Int32___) and [SelectRowAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_SelectRowAsync_System_Int32_System_Nullable_System_Boolean__) method is not supported in infinite scrolling. |
289 | | -* Infinite scrolling is not compatible with the following features: |
| 271 | +* Due to browser element height limitations, the maximum number of records the Grid can load is constrained by browser capabilities. |
| 272 | +* A static height must be set for the component or its parent container when using infinite scrolling. Using 100% height works only if both the Grid and its parent have explicit heights. |
| 273 | +* The combined height of the initially loaded rows must exceed the viewport height for content to scroll. |
| 274 | +* With infinite scrolling, copy-paste and drag-and-drop apply only to items within the current viewport. |
| 275 | +* Cell selection is not persisted in cache mode. |
| 276 | +* Group records cannot be collapsed in cache mode. |
| 277 | +* Lazy load grouping with infinite scrolling does not support cache mode; infinite scrolling applies only to parent-level caption rows in this scenario. |
| 278 | +* In normal grouping, infinite scrolling is not supported for child items during expand/collapse; all child items load when caption rows are toggled. |
| 279 | +* Aggregates and total group items reflect the current view items; this is expected with on-demand data loading. |
| 280 | +* Programmatic selection using [SelectRowsAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_SelectRowsAsync_System_Int32___) and [SelectRowAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_SelectRowAsync_System_Int32_System_Nullable_System_Boolean__) is not supported in infinite scrolling. |
| 281 | +* Infinite scrolling is not compatible with: |
290 | 282 | 1. Batch editing |
291 | 283 | 2. Normal editing |
292 | 284 | 3. Row template |
293 | 285 | 4. Row virtual scrolling |
294 | 286 | 5. Detail template |
295 | 287 | 6. Hierarchy features |
296 | 288 | 7. Autofill |
297 | | -* Limitations of row drag and drop with infinite scrolling |
298 | | - 1. In cache mode, the Grid refreshes automatically if the content's **tr** element count exceeds the cache limit of the Grid's content after the drop action. |
299 | | - 2. When performing row drag and drop with lazy load grouping, the Grid will refresh automatically. |
300 | | - 3. In remote data, changes are applied only in the UI. They will be lost once the Grid is refreshed. To restore them, you need to update the changes in your database. By using the [RowDropped](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridEvents-1.html#Syncfusion_Blazor_Grids_GridEvents_1_RowDropped) event, you can send the request to the server and apply the changes in your database. After this, you need to refresh the Grid to show the updated data. |
| 289 | +* Limitations of row drag and drop with infinite scrolling: |
| 290 | + 1. In cache mode, the Grid refreshes automatically if the number of content `<tr>` elements exceeds the cache limit after the drop action. |
| 291 | + 2. With lazy load grouping, the Grid refreshes automatically after row drag and drop. |
| 292 | + 3. For remote data, changes from drag and drop are applied only in the UI and are lost after refresh unless persisted to the server. Use the [RowDropped](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridEvents-1.html#Syncfusion_Blazor_Grids_GridEvents_1_RowDropped) event to commit changes server-side, then refresh the Grid. |
301 | 293 |
|
302 | 294 | ## See also |
303 | 295 |
|
|
0 commit comments