Back to Devexpress

DxGrid.IsDetailRowExpanded(Int32) Method

blazor-devexpress-dot-blazor-dot-dxgrid-dot-isdetailrowexpanded-x28-system-dot-int32-x29.md

latest7.0 KB
Original Source

DxGrid.IsDetailRowExpanded(Int32) Method

Indicates whether the specified detail row is expanded.

Namespace : DevExpress.Blazor

Assembly : DevExpress.Blazor.v25.2.dll

NuGet Package : DevExpress.Blazor

Declaration

csharp
public bool IsDetailRowExpanded(
    int visibleIndex
)

Parameters

NameTypeDescription
visibleIndexInt32

A zero-based integer index that identifies the detail row.

|

Returns

TypeDescription
Boolean

true if the detail row is expanded; otherwise, false.

|

Remarks

Specify the DetailRowTemplate to enable a master-detail relationship in the grid. A user can click a data row’s expand button to expand the data row and access detail data. To do this in code, call the ExpandDetailRow(Int32) method.

To check whether an individual detail row is expanded, use the IsDetailRowExpanded method.

Note

The Grid bound to an Instant Feedback Data Source or GridDevExtremeDataSource loads data asynchronously in small portions (instead of the entire dataset). Before you call the IsDetailRowExpanded method, call the WaitForRemoteSourceRowLoadAsync(Int32) method to ensure that the specified data row is loaded.

The following code snippet checks the first detail row’s expanded state. If the row is expanded, the button click collapses this row and vice versa.

razor
@inject NwindDataService NwindDataService

<DxGrid @ref="Grid" 
        Data="MasterGridData" >
    <Columns>
        <DxGridDataColumn FieldName="ContactName" SortIndex="0" />
        <DxGridDataColumn FieldName="CompanyName" />
        <DxGridDataColumn FieldName="Country" />
        <DxGridDataColumn FieldName="City" />
    </Columns>
    <DetailRowTemplate>
        <NestedGrid_DetailContent Customer="(Customer)context.DataItem" />
    </DetailRowTemplate>
</DxGrid>

<DxButton Click="OnButtonClick" Text="Expand/Collapse the First Detail Row" />

@code {
    IGrid Grid { get; set; }
    object MasterGridData { get; set; }

    protected override async Task OnInitializedAsync() {
        MasterGridData = await NwindDataService.GetCustomersAsync();
    }

    protected override void OnAfterRender(bool firstRender) {
        if(firstRender) {
            Grid.ExpandDetailRow(0);
        }
    }

     void OnButtonClick() {
        if (Grid.IsDetailRowExpanded(0))
            Grid.CollapseDetailRow(0);
        else
            Grid.ExpandDetailRow(0);
    }
}
razor
@inject NwindDataService NwindDataService
<div class="mb-2">
    Contact Phone: @Customer.Phone
</div>
<DxGrid Data="DetailGridData"
        PageSize="5"
        AutoExpandAllGroupRows="true">
    <Columns>
        <DxGridDataColumn FieldName="OrderId" DisplayFormat="d" GroupIndex="0" />
        <DxGridDataColumn FieldName="ProductName" Width="40%" />
        <DxGridDataColumn FieldName="UnitPrice" DisplayFormat="c" />
        <DxGridDataColumn FieldName="Quantity" />
        <DxGridDataColumn FieldName="Discount" DisplayFormat="p0" />
        <DxGridDataColumn FieldName="ExtendedPrice" DisplayFormat="c" />
    </Columns>
    <GroupSummary>
        <DxGridSummaryItem SummaryType="GridSummaryItemType.Sum"
                           FieldName="ExtendedPrice"
                           FooterColumnName="ExtendedPrice" />
    </GroupSummary>
</DxGrid>

@code {
    [Parameter]
    public Customer Customer { get; set; }
    object DetailGridData { get; set; }
    protected override async Task OnInitializedAsync() {
        var invoices = await NwindDataService.GetInvoicesAsync();
        DetailGridData = invoices
            .Where(i => i.CustomerId == Customer.CustomerId)
            .ToArray();
    }
}
csharp
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;

namespace BlazorDemo.Data.Northwind {
    public partial class Customer {
        public Customer() {
            Orders = new HashSet<Order>();
        }

        public string CustomerId { get; set; }
        public string CompanyName { get; set; }
        public string ContactName { get; set; }
        public string ContactTitle { get; set; }
        public string Address { get; set; }
        public string City { get; set; }
        public string Region { get; set; }
        public string PostalCode { get; set; }
        public string Country { get; set; }
        public string Phone { get; set; }
        public string Fax { get; set; }

        public virtual ICollection<Order> Orders { get; set; }
    }
}
csharp
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;

namespace BlazorDemo.Data.Northwind {
    public class Invoice {
        public string ShipName { get; set; }
        public string ShipAddress { get; set; }
        public string ShipCity { get; set; }
        public string ShipRegion { get; set; }
        public string ShipPostalCode { get; set; }
        public string ShipCountry { get; set; }
        public string CustomerId { get; set; }
        public string CustomerName { get; set; }
        public string Address { get; set; }
        public string City { get; set; }
        public string Region { get; set; }
        public string PostalCode { get; set; }
        public string Country { get; set; }
        public string Salesperson { get; set; }
        public int OrderId { get; set; }
        public DateTime? OrderDate { get; set; }
        public DateTime? RequiredDate { get; set; }
        public DateTime? ShippedDate { get; set; }
        public string ShipperName { get; set; }
        public int ProductId { get; set; }
        public string ProductName { get; set; }
        public decimal UnitPrice { get; set; }
        public short Quantity { get; set; }
        public float Discount { get; set; }
        public decimal? ExtendedPrice { get; set; }
        public decimal? Freight { get; set; }
    }
}
csharp
// ...
builder.Services.AddScoped<NwindDataService>();

Implements

IsDetailRowExpanded(Int32)

See Also

DxGrid Class

DxGrid Members

DevExpress.Blazor Namespace