Deselect row by index programmtically

How do I deselect a row programmatically, I see the function this.Grid.SelectRow(index) but I do not see a this.Grid.DeSelectRow(index). When I use this.Grid.SelectRow() it does not unselect a selected row.


1 Reply 1 reply marked as answer

JP Jeevakanth Palaniappan Syncfusion Team July 29, 2021 06:06 AM UTC

Hi Mason, 
 
Greetings from Syncfusion support. 
 
We have validated your query and you can deselect a row programmatically by using the SelectRow method and pass the row index, true. By passing true as the second parameter, it will toggle the corresponding row. Please refer the below code snippet for your reference. 
 
 
<button @onclick="ToggleRow">Select</button> 
 
@using Syncfusion.Blazor.Grids 
 
<SfGrid @ref="Grid" DataSource="@Orders" AllowSelection="true" AllowPaging="true"> 
    <GridSelectionSettings Type="SelectionType.Multiple"></GridSelectionSettings> 
    <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; } 
 
    SfGrid<Order> Grid { get; set; } 
 
    public async Task ToggleRow() 
    { 
        await Grid.SelectRowAsync(1, true); 
    } 
 
    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(); 
    } 
 
    public class Order 
    { 
        public int? OrderID { get; set; } 
        public string CustomerID { get; set; } 
        public DateTime? OrderDate { get; set; } 
        public double? Freight { get; set; } 
    } 
} 
 
 
Get back to us if you have any other queries. 
 
Regards, 
Jeevakanth SP. 


Marked as answer
Loader.
Up arrow icon