MAUI SfDataGrid ScrollToRowIndex not working properly in macOS

We are facing an issue where ScrollToRowIndex is not working properly on macOS when initially the datagrid is loaded. We have prepared a test project where initially the datagrid will scroll to a position when loaded. But this is working on Windows, not on macOS. In our test project, there is a button which will scroll to random positions. This is working on both windows and macOS.


The behavior we are trying to achieve is, initially a row of the datagrid will be selected from the viewmodel. While loading the datagrid, it will scroll to the selected row. Only when the selected row item will be updated from the viewmodel, we will scroll to that position. Selecting a row from the table will not scroll to the position. We can achieve this in windows. But it is not working in macOS. In macOS, the scroll position is not updating for the initial selected row. We have prepared the test project by reproducing the initial state.


Could you please share any work around for this?


2 Replies

MF Mohammed Fahmidur Rahman November 18, 2024 09:02 AM UTC

Test Project


Attachment: SfDataGridSample_b7f7816c.zip


SD Sethupathy Devarajan Syncfusion Team November 18, 2024 11:15 AM UTC

Hi Mohammed Fahmidur Rahman,
 

You are facing an issue where ScrollToRowIndex is not working properly on macOS when the DataGrid is initially loaded. You can resolve this issue by using the DataGridLoaded event instead of the Loaded event. We have shared the code snippet and the modified sample for your reference.


Code snippet:

Xaml code
<syncfusion:SfDataGrid x:Name="sfGrid"

                       GridLinesVisibility="Both"

                       HeaderGridLinesVisibility="Both"

                       ColumnWidthMode="Auto"

                       SortingMode="Single"

                       AutoGenerateColumnsMode="None"

                       ItemsSource="{Binding Items}"

                       DataGridLoaded="sfGrid_DataGridLoaded"

                       MaximumHeightRequest="400"/>


Xaml.cs

private async void sfGrid_DataGridLoaded(object sender, EventArgs e)

{

    var dataGrid = sender as SfDataGrid;

    _dataGrid = dataGrid;

 

    await dataGrid.ScrollToRowIndex(50, ScrollToPosition.Center, false);

}


Regards,

Sethupathy D.


Attachment: SfDataGridSample_46335890.zip

Loader.
Up arrow icon