<SfRadioButton @onchange="OnGridSelectionTypeChange" Label="Single" Name="options" @bind-Checked="gridSelectionType" Value="single" ></SfRadioButton>
<SfRadioButton @onchange="OnGridSelectionTypeChange" Label="Multiple" Name="options" @bind-Checked="gridSelectionType" Value="multiple"></SfRadioButton>
A string to store radio buttons checked value
private string gridSelectionType = "multiple";Radio buttons change event handlerprivate void OnGridSelectionTypeChange()
{
ShowGrid = false;
StateHasChanged();
selectionType = (gridSelectionType == "single" ? SelectionType.Single : SelectionType.Multiple);
testGrid.SelectionSettings.Type = selectionType;
ShowGrid = true;
StateHasChanged();
}@if (ShowGrid){<SfGrid ...>...<GridSelectionSettings Type="@selectionType"></GridSelectionSettings>...<GridColumns>...<GridColumns>...</SfGrid>}Everything work well, I can switch between Single and Multiple selection type, until I want to add a checkbox column@if (ShowGrid){<SfGrid ...>...<GridSelectionSettings Type="@selectionType"></GridSelectionSettings>...<GridColumns>if (selectionType == SelectionType.Multiple)
{
<GridColumn Type="ColumnType.CheckBox" Width="50"></GridColumn>
}...<GridColumns>...</SfGrid>}Despite the CheckBox column can show or hide as I want, the selection type was always MultipleHow to fix this?Best regards
|
<SfGrid @ref="Grid" DataSource="@Orders" AllowSelection="true" AllowPaging="true">
<GridSelectionSettings Type="@selectionType"></GridSelectionSettings>
@if (selectionType == Syncfusion.Blazor.Grids.SelectionType.Multiple)
{
<GridColumns>
<GridColumn Type="ColumnType.CheckBox" Width="50"></GridColumn>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn>
<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>
</GridColumns>
}
else
{
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn>
<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>
</GridColumns>
}
</SfGrid>
@code{
public List<Order> Orders { get; set; }
private string gridSelectionType = "multiple";
SfGrid<Order> Grid { get; set; }
public Syncfusion.Blazor.Grids.SelectionType selectionType { get; set; } = Syncfusion.Blazor.Grids.SelectionType.Multiple;
private async Task OnGridSelectionTypeChange()
{
await Grid.ClearSelection();
selectionType = (gridSelectionType == "single" ? Syncfusion.Blazor.Grids.SelectionType.Single : Syncfusion.Blazor.Grids.SelectionType.Multiple);
StateHasChanged();
}
|