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();
}
}
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
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.
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