Datagrid SelectRowAsync not changing selection

Hello,


I have a datagrid and inside of an event handler I am trying to update the selected rows of of the grid. When I call SelectRowAsync(index) the grid objects SelectedRecords, SelectedRowIndex, and SelectedRowIndexes all remain unchanged. When an item is added to this collection I want it to be be selected by default and not deselect other items. 



<SfGrid @ref="_dataGrid" DataSource="@AppState.StrategyIndicators" AllowSelection="true" AllowPaging="true">
    <GridSelectionSettings CheckboxOnly="true" PersistSelection="true" Type="Syncfusion.Blazor.Grids.SelectionType.Multiple"></GridSelectionSettings>
    <GridEvents TValue="BaseIndicator"
                RowSelected="OnIndicatorSelected"
                RowDeselected="OnIndicatorDeselected">
    </GridEvents>
    <GridColumns>
        <GridColumn Type="ColumnType.CheckBox" Width="50">
            <HeaderTemplate></HeaderTemplate>
        </GridColumn>


        <GridColumn Field=@nameof(BaseIndicator.DisplayName) HeaderText="Indicator" TextAlign="TextAlign.Left" IsPrimaryKey="true" Width="150"></GridColumn>
        <GridColumn Width="50">
            <Template>
                @{
                    var indicator = (context as BaseIndicator);
                    <SfButton @onclick="@(() => OnEditClick(indicator))">Edit</SfButton>
                }
            </Template>
        </GridColumn>
    </GridColumns>
</SfGrid>



@code {


    private SfGrid<BaseIndicator> _dataGrid { get; set; }
 
    private void OnStrategyIndicatorAdded(BaseIndicator indicator)
    {
        _dataGrid.Refresh();
        var index = AppState.StrategyIndicators.IndexOf(indicator);
        _dataGrid.SelectRowAsync(index);
        StateHasChanged();
    }
}

1 Reply

MS Monisha Saravanan Syncfusion Team July 11, 2022 11:47 AM UTC

Hi Leland,


Greetings from Syncfusion support.


We have checked your query and we suspect that you are trying to update the selected rows by using a button click event and we could see that you have used SelectRowAsync method from your shared code snippet. We would like to inform that calling SelectRowAsync method will clear all the previous selected records and will select only the current record. Instead of using selectRowAsync we suggest you to use SelectRowsAsync method of DataGrid to select multiple rows. Kindly check the attached UG for your reference.


Reference: https://blazor.syncfusion.com/documentation/datagrid/selection#multiple-selection-based-on-condition

https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_SelectRowsAsync_System_Double___


If we misunderstood your query or if the reported query is not resolved then kindly share the below details to validate further at our end.


  1. Share us the video demonstration of the issue.
  2. You have mentioned that you are adding an item. Kindly explain the way you have added item to an collection.
  3. Kindly share us when you are calling the OnStrategyIndicatorAdded event.
  4. Share us some more details regarding your exact query.
  5. If possible kindly share us the issue reproduceable sample.


The above-requested details will be very helpful for us to validate the reported query at our end and provide the solution as early as possible.



Regards,

Monisha



Loader.
Up arrow icon