Identifying whether a row is visible (with MVVM)

Hi,

I have a datagrid which shows lots of realtime data which is calculated by very CPU intensive calculations. I had an idea to reduce CPU usage which is to only calculate these values for rows that are visible on the screen. Is it possible to determine whether a row is visible on the screen and bind it to the row's view model? For example I would want to be able to implement:

public class RowViewModel
{
    // True when row is visible in the view
    public bool IsVisible { get; set; }


If I scroll down and the row goes out of view, IsVisible should become false.

If not, any advice on how to determine a row's visibility on screen would helpful. Thanks.

Zia


3 Replies 1 reply marked as answer

MA Manikanda Akash Munisamy Syncfusion Team November 21, 2024 12:38 PM UTC

Hi Zia,
 
We have reviewed your scenario, where the application features an SfDataGrid displaying real-time data derived from CPU-intensive calculations. To optimize performance, you proposed calculating values only for the rows currently visible on the screen.
 
To meet your requirement, we have implemented a workaround using the RowGenerator.Items property in the ScrollChanged event. This approach dynamically modifies a flag variable to indicate whether a row is currently visible within the viewport. The flag is reset to false when rows are scrolled out of view, ensuring efficient resource usage.
 
We have attached a prepared sample for your reference.
 
If we have misunderstood your request or if your requirements differ, kindly provide additional details. This will help us better understand the issue and deliver a more accurate solution.

Regards,
Manikanda Akash

Attachment: SfDataGrid_Demo4_8_67db7810.zip

Marked as answer

ZI Zia November 21, 2024 09:52 PM UTC

Thank you, this has worked for me.



MA Manikanda Akash Munisamy Syncfusion Team November 22, 2024 07:46 AM UTC

Hi Zia,

We are glad that your requirement was achieved. Hence, we mark this forum as solved. Please feel free to create a new forum, and we will be happy to assist you.

Regards,
Manikanda Akash

Loader.
Up arrow icon