Change grid selection type at runtime does not work if there is a CheckBox column type

Hi

I created radio buttons to select grid selection type at runtime
<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 handler
private 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 Multiple
How to fix this?
Best regards

3 Replies 1 reply marked as answer

JP Jeevakanth Palaniappan Syncfusion Team March 23, 2021 05:50 AM UTC

Hi Thinh, 
 
Greetings from Syncfusion support. 
 
We have validated your query and we have considered it as a bug and logged the defect report “Grid behaves as Multiple Select when dynamically changing SelectionType to Single and removing checkbox column”. Thank you for taking the time to report this issue and helping us improve our product. At Syncfusion, we are committed to fixing all validated defects (subject to technological feasibility and Product Development Life Cycle ) and including the defect fix in our upcoming patch release which is expected to be rolled out on or before end of April, 2021.  Until then we appreciate your patience. 
   
You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link.       
 
 
Regards, 
Jeevakanth SP. 



TH Thinh June 10, 2021 10:05 AM UTC

Hi

If  I set checkbox column like this

 @if (selectionType == SelectionType.Multiple)
 {
     <GridColumn  Type="ColumnType.CheckBox" Width="50"></GridColumn>
 }

then when SelectionType is Multiple, the checkbox column always show at the end of column list, I want checkbox column show at the beginning.

If I set checkbox column like this

<GridColumn Visible="@(selectionType == SelectionType.Multiple)" Type="ColumnType.CheckBox" Width="50"></GridColumn>

then the checkbox column show / hide normally, but the grid still in Multiple mode when switch to Single mode








JP Jeevakanth Palaniappan Syncfusion Team June 11, 2021 06:49 AM UTC

Hi Thinh, 

We have checked your query and we suggest you to render the GridColumns in if-else as like below to resolve the reported problem. Also call the ClearSelection method before changing the SelectionType to render the SelectAll checkbox with UnCheck state, on changing the SelectionType from Single to Multiple. Please refer the below code for your reference. 

<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.CustomerID) HeaderText="Customer Name" Width="150"></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.CustomerID) HeaderText="Customer Name" Width="150"></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(); 
    } 



Please get back to us if you have any other queries. 

Regards, 
Jeevakanth SP. 


Marked as answer
Loader.
Up arrow icon