How to get all selected cells?

I am testing multiple cell selection of Blazor SfGrid. I want to know how to get all selected cells. I tried to use CellSelected and CellDeselected methods to get selected cells. But the CellDeselected looks not working correctly. So I don't know what can do.


7 Replies

VN Vignesh Natarajan Syncfusion Team August 19, 2021 05:41 AM UTC

Hi Telossoft,  
 
Thanks for contacting Syncfusion support.  
 
Query: “I want to know how to get all selected cells. I tried to use CellSelected and CellDeselected methods to get selected cells 
 
We have analyzed your query and we are quite unclear about your requirement. So kindly share the following details.  
 
  1.  Do you want to select all cells in a row.? If yes, then you can use Row Selection mode to select the entire records.
  2. Do you want to programmatically select the cell/rows in Grid.
  3. Share more details about the requirement.
 
Also we would like to inform that CellSelected and CellDeselected are the Grid events which will gets triggered when cell is selected or deselected. They cannot be used as method to select the cells. So kindly share the above requested details which will be very helpful in understanding the requested query and provide solution as early as possible.   
 
Regards, 
Vignesh Natarajan 



TE telossoft August 19, 2021 06:18 AM UTC

Thank you for your reply.

Please look at the image below. There are 4 cells selected, I want to know which cells are selected, then I can update the values of selected cells.




VN Vignesh Natarajan Syncfusion Team August 20, 2021 08:29 AM UTC

Hi Telossoft, 
 
Thanks for the update.  
 
We have analyzed your and we do not have direct support to find the selected cell details in Grid. So we have maintained the Selectedcell details in global variable and on external button click. We have updated the cell using the UpdateCellAsync method using selected cell tuple value.  
 
Refer the below code example.  
 
<SfButton OnClick="Select" Content="Update Selected"></SfButton> 
  
<SfGrid @ref="GridInstance" DataSource="@Orders" AllowSelection="true" AllowPaging="true"> 
    <GridEvents CellSelected="OnCellSelect" TValue="Order"></GridEvents> 
    <GridEditSettings AllowEditing="true" Mode="EditMode.Batch"></GridEditSettings> 
    <GridSelectionSettings Mode="SelectionMode.Cell" Type="Syncfusion.Blazor.Grids.SelectionType.Multiple"></GridSelectionSettings> 
    <GridColumns> 
        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" 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 SfGrid<Order> GridInstance { getset; } 
  
    public List<Order> Orders { getset; } 
  
    public List<Tuple<doubledouble>> SelectedCells { getset; } = new List<Tuple<doubledouble>>(); 
  
    public async Task OnCellSelect(CellSelectEventArgs<Order> Args) 
    { 
        if (!SelectedCells.Contains(new Tuple<doubledouble>(Args.RowIndex, Args.CellIndex))) 
        { 
            SelectedCells.Add(new Tuple<doubledouble>(Args.RowIndex, Args.CellIndex)); 
        } 
    } 
  
     public async Task Select() 
    { 
        foreach (var cell in SelectedCells) 
        { 
            var column = GridInstance.Columns[Convert.ToInt32(cell.Item2)].Field; 
            await GridInstance.UpdateCellAsync(cell.Item1, column, "updated"); 
        } 
    } 
 
 
Kindly refer the below sample for your reference 
 
 
Please get back to us if you have further queries. 
 
Regards, 
Vignesh Natarajan   
 
 



TE telossoft August 20, 2021 09:31 AM UTC

Thank you for your reply.  But I'd to say sorry that your solution are not correct. It just keep append the new selected cell to the selected cells but not remove the deselected cells.

I add below code to display the selected cells. please notice at the text below the update button.

```

<div>selected: @string.Join(", ", SelectedCells.Select(x => $"[{x.Item1}, {x.Item2}]"))</div>

```

 






VN Vignesh Natarajan Syncfusion Team August 23, 2021 05:54 AM UTC

Hi Teossoft,  
 
Sorry for the inconvenience caused. 
 
Query: “It just keep append the new selected cell to the selected cells but not remove the deselected cells. 
 
We have analyzed the reported query and we are able to reproduce the reported issue at our end also. It occurred due to wrong indexes being returned in the CellDeselected event of Grid. We have confirmed the reported query as a bug and logged the defect report “CellDeselected event return wrong cell and rowindex for the same. Thank you for taking the time to report this issue and helping us improve our product. Fix for the defect will be included in our weekly release which is expected to be rolled out by end of September 2021. We will update you once the release is rolled out.     
        
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.        
    
 
Till then we appreciate your patience.  
 
Regards, 
Vignesh Natarajan 



VN Vignesh Natarajan Syncfusion Team October 5, 2021 10:55 AM UTC

Hi Telossoft,  
 
Sorry for the inconvenience caused.  
 
Due to unforeseen circumstances, we are unable to include the fix for the reported issue “CellDeselected event return wrong cell and rowindex”  in our weekly patch release as promised. Fix for issue will be included in our weekly patch release which is excepted to be rolled out by end of October 2021 
 
 
Till then we appreciate your patience.   
 
Regards, 
Vignesh Natarajan 
 



VN Vignesh Natarajan Syncfusion Team November 1, 2021 10:01 AM UTC

Hi Telossoft 
 
We are glad to announce that our latest release(19.3.0.47) has been successfully rolled out. We have included the fix for this issue CellDeselected event return wrong cell and rowindexin our last (19.3.0.46) version release. So please upgrade to our latest release for latest fixes and features.  
 
 
 
We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance.   
    
Regards,              
Vignesh Natarajan 


Loader.
Up arrow icon