We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Getting selected rows in grid

Hello

When trying to get the selected rows the list is empty. My code is: 

@page "/"
@using Data
@using Syncfusion.EJ2.Blazor.Grids
@using Syncfusion.EJ2.Blazor.Popups
@using Newtonsoft.Json;

<button @onclick=@(() => this.GetRows())>get</button>

@this.Temp

<EjsGrid @ref=this.defaultGrid DataSource=@this.gridData AllowSelection="true">
    <GridSelectionSettings PersistSelection="true"></GridSelectionSettings>
    <GridColumns>
        <GridColumn Type="checkbox" Width="50"></GridColumn>
        <GridColumn Field=@nameof(OrdersDetails.CustomerID) HeaderText="Customer Name"></GridColumn>
        <GridColumn Field=@nameof(OrdersDetails.OrderDate) HeaderText="Order Date" Format="yMd"></GridColumn>
        <GridColumn Field=@nameof(OrdersDetails.Freight) HeaderText="Freight" Format="C2"></GridColumn>
        <GridColumn Field=@nameof(OrdersDetails.ShipCountry) HeaderText="Ship Country"></GridColumn>
    </GridColumns>
</EjsGrid>

@functions{
    EjsGrid defaultGrid;

    public List<OrdersDetails> gridData { get; set; }

    public object Temp { get; set; }

    public void GetRows()
    {
        var temp = this.defaultGrid.GetSelectedRows();

        temp.GetAwaiter().OnCompleted(() =>
                {
                    this.Temp = temp.Result;
                    this.Invoke(this.StateHasChanged);
                });
    }

    protected override async Task OnInitAsync()
    {
        await base.OnInitAsync();

        this.gridData = OrdersDetails.GetAllRecords();
    }
}


2 Replies

VN Vignesh Natarajan Syncfusion Team July 10, 2019 04:04 PM UTC

Hi Ivan, 

Thanks for contacting Syncfusion forum.  

Query: “When trying to get the selected rows the list is empty 

We have analyzed the provided code example and we are able to reproduce the reported behavior at our end while preparing a sample using your code example. Currently we are validating your scenario and we will update you the further details by 11th July 2019.  

Till then we appreciate your patience.   

Regards, 
Vignesh Natarajan. 



VN Vignesh Natarajan Syncfusion Team July 11, 2019 12:21 PM UTC

Hi Ivan,  

Thanks for the patience. 

Query: “When trying to get the selected rows the list is empty 

We have validated the reported issue at our end by preparing a sample using your code example and we are able to reproduce the reported issue. We have considered the reported query as a bug and it will be included in our next patch release which is expected to be roll out on or before 23rd July 2019.  

You can track the status of the issue using the below feedback 


Till then we appreciate your patience.  

As a workaround you can get the DOM elements using RowSelectedEvents. It will be triggered for each row selection.  

Refer the below code example 

<EjsGrid @ref=defaultGrid DataSource=@gridData RowSelected="rowselect" AllowSelection="true"> 
………………………………………. 
</EjsGrid> 
 
public List<DOM> Temp { get; set; } 
public List<Orders> order = new List<Orders>(); 
public void rowselect(RowSelectEventArgs args) 
{ 
    this.Temp.Add(args.Row); 
} 

Note: GetSelectedRows() method will return the row elements (i.e) DOM elements in form of array collection. If you want to get the selected record details, we suggest you to achieve your requirement using GetSelectedRecords().  
 
Refer the below screenshot for your reference 

public void GetRows() 
{ 
    var temp = this.defaultGrid.GetSelectedRecords(); // return the details of selceted record 
 
    temp.GetAwaiter().OnCompleted(() => 
    { 
        this.Temp = temp.Result; // here you can get the selected row datas in form list of objects. 
        this.Invoke(this.StateHasChanged); 
    }); 
} 

Please get back to us if you have further queries.  
    
Regards, 
Vignesh Natarajan. 


Loader.
Live Chat Icon For mobile
Up arrow icon