Disable SelectAll checkbox on grids set as SelectionType.Single

Hi,

I have a datagrid that is used in multiple components, sometimes it is SelectionType.Single and other times 

SelectionType.Multiple, governed by a parameter. In another post I found the css to disable the select all button

.e-grid .e-gridheader tr th:first-child {

        color: #F5F5F5;

        pointer-events: none;

}

but the only way I have found to disable for SelectionType.Single only is to replicate the grid with a different id and an if statement around it and to put the css specifically against that grid id. This all seems a bit clumsy and I'm sure there must be a more efficient way but I can't find it or work it out. 

In the other post I read there were criteria in the code behind limiting the selection in the grid but that's not relevant here; I just want 'if it's multiple allow select all' and 'if it's single don't allow select all'. How is this possible?

Thanks,

Ben


3 Replies

VN Vignesh Natarajan Syncfusion Team November 12, 2021 01:02 PM UTC

Hi Ben,  
 
Thanks for contacting Syncfusion support.  
 
Query: “I just want 'if it's multiple allow select all' and 'if it's single don't allow select all'. How is this possible? 
 
We have analyzed your query and we understand that you want to toggle between the Select All checkbox based on Selection. We have achieved your requirement using the Boolean variable. Refer the below code example.  
 
<button @onclick="Toggled">Toggle Selection Type</button> 
  
<SfGrid DataSource="@Orders" AllowSelection="true" AllowPaging="true"> 
    <GridSelectionSettings Type="@GridSelectionType"></GridSelectionSettings> 
    <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> 
</SfGrid> 
  
@if (CanApply) 
{ 
    <style> 
        .e-grid .e-gridheader tr th:first-child { 
            color#F5F5F5; 
            pointer-eventsnone; 
        } 
    </style> 
} 
  
@code{ 
    public List<Order> Orders { getset; } 
    public void Toggled() 
    { 
        GridSelectionType = (GridSelectionType == SelectionType.Single) ? SelectionType.Multiple : SelectionType.Single; 
        CanApply = GridSelectionType == SelectionType.Single ? true : false ; 
    } 
    public bool CanApply { getset; } 
  
    public SelectionType GridSelectionType { getset; } = SelectionType.Single; 
  
    protected override void OnInitialized() 
    { 
        Orders = Enumerable.Range(1, 75).Select(x => new Order() 
        { 
            OrderID = 1000 + x, 
            CustomerID = (new string[] { "ALFKI""ANANTR""ANTON""BLONP""BOLID" })[new Random().Next(5)], 
            Freight = 2.1 * x, 
            OrderDate = DateTime.Now.AddDays(-x), 
        }).ToList(); 
        if (GridSelectionType == SelectionType.Single) 
        { 
            CanApply = true; 
        } 
        else 
        { 
            CanApply = false; 
        } 
    } 
 
 
Refer the below sample for your reference 
 
 
Please get back to us if you have further queries.    
 
Regards, 
Vignesh Natarajan 



BE Ben November 16, 2021 04:15 AM UTC

Hi Vignesh,


Thanks for this - the information provided helped me achieve this.

But adding an if to a style isn't ideal - are there any plans to implement what I'd consider logical functionality for the control...if it is SelectionType.Single then Select All is disabled by default?

Cheers,

Ben



VN Vignesh Natarajan Syncfusion Team November 16, 2021 06:25 AM UTC

Hi Ben, 
 
Thanks for the update. 
 
Query: “ are there any plans to implement what I'd consider logical functionality for the control...if it is SelectionType.Single then Select All is disabled by default? 
 
We understand your requirement, but we would like to inform you that CheckBox column is used for selection purpose only. When CheckBox column is defined, then multiple selection is enabled in Grid. Specifying SelectionType as single will taken inconsideration and prevent the user from selection more than one record (with default settings). This is default behavior of Grid with checkbox column. Multiple selection will be enabled by default. Hence we have do not have plans to disable SelectAll checkox when SelectionType is Single. 
 
Please get back to us if you have further queries.  
 
Regards, 
Vignesh Natarajan  


Loader.
Up arrow icon