Get Expanded Row

How to get expanded row or rows in SfGrid​?

<SfGrid AllowResizing="true" ID="GrdProvidersList" @ref="GridProvidersList" DataSource="@ProvidersList" AllowPaging="true" AllowSorting="true" AllowExcelExport="true" Toolbar="@(new List<string>() { "ExcelExport",  "Add", "Edit", "Delete", "Update", "Cancel"})">
                <GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true" Mode="EditMode.Normal" ShowDeleteConfirmDialog="true" />
                <GridEvents OnToolbarClick="ToolbarClickHandler" TValue="ProvidersListModel"
                            OnActionBegin="Begin"></GridEvents>
                <GridPageSettings PageSize="20"></GridPageSettings>

                <GridTemplates>
                    <DetailTemplate>
                        @{
                            ProvidersListModel item = context as ProvidersListModel;
                            <div style="padding: 25px">
                                <SfGrid DataSource="item.ProviderAddresses" ID="GrdProvidersAddressList" @ref="GrdProviderAddressList" AllowPaging="true" AllowSelection="true"
                                        Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel"})">
                                    <GridPageSettings PageSize="20"></GridPageSettings>
                                    <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Batch" ShowConfirmDialog="true"
                                                      NewRowPosition="NewRowPosition.Top"
                                                      ShowDeleteConfirmDialog="true"></GridEditSettings>
                                    <GridEvents TValue="ProviderAddress"
                                                OnBatchSave="ProviderAddressBatchSave"></GridEvents>
                                    <GridColumns>
                                        <GridColumn Field=@nameof(ProviderAddress.Id) HeaderText="ID" Width="50" IsPrimaryKey="true" Visible="false" />
                                        <GridColumn Field=@nameof(ProviderAddress.City) HeaderText="City" Width="50" />
                                        <GridColumn Field=@nameof(ProviderAddress.State) HeaderText="State" Width="50" />
                                        <GridColumn Field=@nameof(ProviderAddress.ZipCode) HeaderText="ZipCode" Width="50" />
                                        <GridColumn Field=@nameof(ProviderAddress.StreetLine1) HeaderText="Street Line 1" Width="50" />
                                        <GridColumn Field=@nameof(ProviderAddress.StreetLine2) HeaderText="Street Line 2" Width="50" />
                                        <GridColumn Field=@nameof(ProviderAddress.CompleteAddress) HeaderText="Address" Width="50" />
                                    </GridColumns>
                                </SfGrid>
                            </div>
                        }
                    </DetailTemplate>
                </GridTemplates>


                <GridColumns>
                    <GridColumn HeaderText="ID" Field="@nameof(ProvidersListModel.ProviderId)" Visible="false" IsPrimaryKey="true" />
                    <GridColumn HeaderText="Name" Field="@nameof(ProvidersListModel.ProviderName)" Width="200px" EditType="EditType.DefaultEdit" />
                    <GridColumn HeaderText="Facility Name" Field="@nameof(ProvidersListModel.FacilityName)" Width="200px" EditType="EditType.DefaultEdit" />
                    <GridColumn HeaderText="Product" Field="@nameof(ProvidersListModel.Product)" Width="100px" EditType="EditType.DefaultEdit" AllowResizing="true" />
                    <GridColumn HeaderText="Patient Type" Field="@nameof(ProvidersListModel.PatientType)" Width="100px" EditType="EditType.DefaultEdit" AllowResizing="true" />
                    <GridColumn HeaderText="Languages Spoken" Field="@nameof(ProvidersListModel.LanguagesSpoken)" Width="100px" EditType="EditType.DefaultEdit" AllowResizing="true" />
                    <GridColumn HeaderText="New Patient Accepted" Field="@nameof(ProvidersListModel.PatientType)" Width="100px" EditType="EditType.DefaultEdit" AllowResizing="true" />
                    <GridColumn HeaderText="Certification" Field="@nameof(ProvidersListModel.Certification)" Width="100px" EditType="EditType.DefaultEdit" AllowResizing="true" />
                    <GridColumn HeaderText="Email" Field="@nameof(ProvidersListModel.Email)" Width="100px" EditType="EditType.DefaultEdit" AllowResizing="true" />
                    <GridColumn HeaderText="Cellnumber" Field="@nameof(ProvidersListModel.Cellnumber)" Width="100px" EditType="EditType.DefaultEdit" AllowResizing="true" />
                    <GridColumn HeaderText="OfficeNumber" Field="@nameof(ProvidersListModel.OfficeNumber)" Width="100px" EditType="EditType.DefaultEdit" AllowResizing="true" />
                    <GridColumn HeaderText="TimeZone" Field="@nameof(ProvidersListModel.TimeZone)" Width="100px" EditType="EditType.DefaultEdit" AllowResizing="true" />
                    <GridColumn HeaderText="AcceptedInsurance" Field="@nameof(ProvidersListModel.AcceptedInsurance)" Width="100px" EditType="EditType.DefaultEdit" AllowResizing="true" />
                </GridColumns>
            </SfGrid>

Let me know which event to override in order to get expanded Row or Rows.



5 Replies

VN Vignesh Natarajan Syncfusion Team September 22, 2021 06:16 AM UTC

Hi Faizan,  
 
Greetings from Syncfusion support.  
 
Query: “How to get expanded row or rows in SfGrid​? 
 
We have analyzed your query and we would like to inform you that we do not have direct method to find the expanded record details in Grid. So we have used JSRuntime to call a JavaScript method and find the expanded record details using CSS Selectors and returned those values.  
 
Refer the below code example.  
 
<SfButton OnClick="Exp" Content="Expand All Details"></SfButton> 
  
<SfGrid @ref="Grid" DataSource="@Employees" Height="315px"> 
    . . . . . .. . . .  
</SfGrid> 
  
@code{ 
  
    SfGrid<EmployeeData> Grid { getset; } 
  
    public async Task Exp() 
    { 
        int[] expanded = await Runtime.InvokeAsync<int[]>("expandedRows", Grid.ID); 
    } 
 
[rowdetails.js] 
 
var rowInfo = [];function expandedRows(id) {    rowInfo = [];    var instance = document.getElementById(id);    //find the row first child which is detail cell    for (var i = 0; i < instance.querySelectorAll("tr.e-row td:not(.e-rowcell):first-child").length; i++) {        // check for aria-expanded attribute which returns true or false based on detail template expanded        if (instance.querySelectorAll("tr.e-row td:not(.e-rowcell):first-child")[i].getAttribute("aria-expanded") === "true") {            //push that particular index             rowInfo.push(i);        }    }    return rowInfo;}
 
 
For your convenience we have attached the sample using above code example.  
 
 
Please get back to us if you have further queries.   
 
Regards, 
Vignesh Natarajan 



FM Faizan Mubasher September 22, 2021 06:26 AM UTC

Thanks for reply!

Actually we are trying to Batch Edit Master Detail Grid. For single level Grid it is easy, but when there is master detail Grid it becomes tricky. Can you please provide any example of Batch Edit of Master Detail Grid. Specially Grid with expandable rows.


Thanks



VN Vignesh Natarajan Syncfusion Team September 23, 2021 06:11 AM UTC

Hi Faizan,  
 
Thanks for the update.  
 
Query: “Can you please provide any example of Batch Edit of Master Detail Grid. Specially Grid with expandable 
 
As per your requirement we have prepared a sample to perform Batch editing in Master Detail Grid (hierarchy structure) and sample can be downloaded from below  
 
 
Refer our UG documentation for your reference 
 
 
Kindly refer the below sample and get back to us with more details if you have further queries.   
 
Regards, 
Vignesh Natarajan 



TT Thomas Trummer replied to Vignesh Natarajan November 22, 2021 09:47 AM UTC

Hi,


is it also possible to expand specific rows by javascript?


By default all groups are collapsed after data loaded

I also know that there is a function to expand all groups but I only want to expand the first group column.

And if possible it would be nice to keep them expanded even if a scroll, sort, ... action was performed


Thanks



VN Vignesh Natarajan Syncfusion Team November 23, 2021 07:16 AM UTC

Hi Thomas,  
 
Thanks for contacting Syncfusion support.  
 
Query: “is it also possible to expand specific rows by javascript?” && I only want to expand the first group column And if possible it would be nice to keep them expanded even if a scroll, sort, ... action was performed 
 
Yes, we have achieved your requirement to expand first group in Grid by calling a JavaScript method using JSInterop. In the JavaScript method, we have clicked the expand icon to open the particular group. Refer the below code example.  
 
@inject IJSRuntime Runtime  
  
<SfGrid @ref="Grid" DataSource="Orders" AllowSorting="true" AllowFiltering="true" AllowGrouping="true"> 
    <GridEvents DataBound="OnDataBound" TValue="Order"></GridEvents> 
    <GridGroupSettings Columns="@Cols"></GridGroupSettings>     
    <GridColumns> 
        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="@TextAlign.Center" Width="140"></GridColumn> 
        <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn> 
        <GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" Width="150"></GridColumn> 
    </GridColumns> 
</SfGrid> 
  
@code{ 
  
    SfGrid<Order> Grid { getset; } 
    public string[] Cols = new string[] { "CustomerID" }; 
    public List<Order> Orders { getset; } 
  
    public async Task OnDataBound() 
    { 
        //to collapse all the groups.  
        await Grid.GroupCollapseAll(); 
        //send gridid, grouped column name and values of particular group you want to expand. 
        await Runtime.InvokeVoidAsync("ExpandGroup", Grid.ID); 
    } 
 
[Host.cshtml] 
 
<head>.. . . . .    <link rel='nofollow' href="_content/Syncfusion.Blazor/styles/material.css" rel="stylesheet" />    <script src="~/GroupExpand.js"></script></head>
 
[GroupExpand.js] 
 
function ExpandGroup(GridId) {        // get instance of the Gridcontent    var gridObj = document.getElementById(GridId).querySelector(".e-gridcontent")    gridObj.querySelectorAll(".e-recordpluscollapse")[0].querySelector(".e-icon-grightarrow").click();   }
 
 
Also we have implemented above requirement using the DataBound event which will be triggered after a certain data operations. Kindly refer the below sample code example.  
 
 
Please get back to us if you have further queries or if above solution does not resolve your query. 
 
Regards, 
Vignesh Natarajan 


Loader.
Up arrow icon