Performance best practices for Angular TreeGrid component
10 Sep 20253 minutes to read
This article provides actionable strategies for optimizing the loading performance of the Angular TreeGrid, especially when working with complex hierarchical data containing many columns and rows. It outlines methods for efficiently binding large datasets while maintaining an optimal user experience and performance, even under demanding scenarios.
Improving loading performance with large datasets
The TreeGrid displays hierarchical data using rows and columns. With large data sources, optimizing rendering is critical. For example, binding a dataset with 10 parent records, each having 10 child records, and 10 columns results in 1,100 DOM elements rendered. To maximize performance, limit the number of rows and columns rendered simultaneously, reducing browser workload and enabling TreeGrid to handle extensive data without degradation.
Enhance performance with paging
Enable paging to divide the data into pages and limit the number of rows rendered at a time. This improves both load times and user responsiveness, especially with deeply nested data. For guidance on configuring paging, see the TreeGrid Paging documentation.
Optimize performance with row virtualization and infinite scrolling
Use virtualization or infinite scrolling to manage large hierarchical datasets efficiently:
-
Virtualization: Only the rows visible in the viewport are rendered, rather than the entire dataset, greatly increasing performance with large or deeply nested data. For details, see the TreeGrid Virtual Scrolling documentation.
-
Infinite Scrolling: Loads data on demand as the user scrolls, fetching new blocks of rows when reaching the end of the vertical scroller, and keeping the TreeGrid responsive. See the TreeGrid Infinite Scrolling documentation.
Column virtualization for large numbers of columns
The column virtualization feature optimizes column rendering by displaying only those within the current viewport; additional columns become visible when horizontally scrolled. This is essential for TreeGrids with many columns to reduce initial load time and DOM size.
Both row and column virtualization can be combined, dynamically loading only visible rows and columns for maximum efficiency and improved grid responsiveness, even in complex hierarchical scenarios. See the TreeGrid Column Virtualization documentation for more details.
Using column templates for efficient custom cell content
When customizing TreeGrid columns with images or templates, use the column template feature to avoid rendering delays. Relying on rowDataBound or queryCellInfo events can slow down rendering with large data.
Why choose column templates instead of events?
- Performance Optimization: The rowDataBound and queryCellInfo events are triggered for each row and cell rendering, which can introduce significant delays, especially with large hierarchical datasets.
- Avoid Persistent Elements: Rendering custom elements using events can lead to the persistence of previously rendered elements, potentially increasing rendering times over time.
-
Streamlined Rendering: Column templates enable customization without impacting rendering performance, ensuring a smoother and faster experience.
The Column Template feature allows efficient customization of TreeGrid columns while maintaining optimal performance and rendering speed.
For detailed guidance, refer to the Tree Grid Column Template Documentation.
Updating cell values without frequent server calls
For live updates or batch editing scenarios, use the setCellValue method to update cell values directly in the UI after initial data binding. This method updates the value in the TreeGrid without sending requests to the server or database, maintaining both performance and a responsive interface.
Optimizing server-side data operations with adaptors
Angular TreeGrid supports adaptors such as OData, ODataV4, WebAPI, and URL for server-side data operations and CRUD functionality. With the DataManager component, remote hierarchical data sources can be efficiently managed and bound.
During server-side operations—such as filtering, sorting, aggregates, and paging—the TreeGrid generates action queries as per the adaptor in use. These queries should be processed on the server, and data returned in a compatible structure. For best results and accurate records, the recommended server-side sequence is:
- Apply filtering to select relevant records.
- Perform sorting on the filtered dataset.
- Compute aggregates if required.
- Apply paging to reduce the result set before sending to the client.
Following this order ensures the TreeGrid loads large datasets efficiently and accurately.
See also
- Browser height limitation in virtual scrolling and solution
- How to improve loading performance by referring individual script and CSS
- How to avoid MaxJsonLength error while passing large amount of records
- Optimizing Angular app performance with multiple grids and templates
- Microsoft Excel limitation when exporting millions of records