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
|
<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.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-events: none;
}
</style>
}
@code{
public List<Order> Orders { get; set; }
public void Toggled()
{
GridSelectionType = (GridSelectionType == SelectionType.Single) ? SelectionType.Multiple : SelectionType.Single;
CanApply = GridSelectionType == SelectionType.Single ? true : false ;
}
public bool CanApply { get; set; }
public SelectionType GridSelectionType { get; set; } = 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;
}
}
|
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