Back to Devexpress

DxGrid.GetGroupSummaryDisplayText(IGridSummaryItem, Int32) Method

blazor-devexpress-dot-blazor-dot-dxgrid-dot-getgroupsummarydisplaytext-x28-devexpress-dot-blazor-dot-igridsummaryitem-system-dot-int32-x29.md

latest9.4 KB
Original Source

DxGrid.GetGroupSummaryDisplayText(IGridSummaryItem, Int32) Method

Gets a group summary item’s display text.

Namespace : DevExpress.Blazor

Assembly : DevExpress.Blazor.v25.2.dll

NuGet Package : DevExpress.Blazor

Declaration

csharp
public string GetGroupSummaryDisplayText(
    IGridSummaryItem item,
    int visibleIndex
)

Parameters

NameTypeDescription
itemIGridSummaryItem

The group summary item.

| | visibleIndex | Int32 |

The group row’s index.

|

Returns

TypeDescription
String

The group summary item’s display text.

|

Remarks

Specify the DisplayText property or handle the CustomizeSummaryDisplayText event to customize the summary display text.

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 GetGroupSummaryDisplayText method, call the WaitForRemoteSourceRowLoadAsync(Int32) method to ensure that the specified data row is loaded.

The following code snippet customizes group rows. These rows contain group field values and summary values that are formatted in italics.

razor
@using Microsoft.EntityFrameworkCore
@inject IDbContextFactory<NorthwindContext> NorthwindContextFactory
@implements IDisposable

<DxGrid Data="@Data"
        ShowGroupPanel="true"
        CustomizeSummaryDisplayText="Grid_CustomizeSummaryDisplayText">
    <Columns>
        <DxGridDataColumn FieldName="Country" GroupIndex="0" Width="200px">
            <GroupRowTemplate>
                <text>@context.DataColumn.FieldName : @context.GroupValue</text>
                @{
                    var summaryItems = context.Grid.GetGroupSummaryItems();
                    if (summaryItems.Any())
                    {
                        <text> (</text>
                        foreach (var i in summaryItems)
                        {
                            <i>@context.Grid.GetGroupSummaryDisplayText(i, context.VisibleIndex)</i>
                        }
                        <text>)</text>
                    }
                }
            </GroupRowTemplate>
        </DxGridDataColumn>
        <DxGridDataColumn FieldName="City" />
        <DxGridDataColumn FieldName="OrderDate" Width="200px" />
        <DxGridDataColumn FieldName="UnitPrice" DisplayFormat="c" Width="120px" />
        <DxGridDataColumn FieldName="Quantity" Width="120px" />
    </Columns>
    <GroupSummary>
        <DxGridSummaryItem SummaryType="GridSummaryItemType.Count" FieldName="Country" />
    </GroupSummary>
</DxGrid>
@* ... *@
@code {
    object Data { get; set; }
    NorthwindContext Northwind { get; set; }
    IGrid Grid1 { get; set; }
    @* ... *@
    protected override void OnInitialized() {
        Northwind = NorthwindContextFactory.CreateDbContext();
        Data = Northwind.Invoices
            .ToList();
    }

    void Grid_CustomizeSummaryDisplayText(GridCustomizeSummaryDisplayTextEventArgs e) {
        e.DisplayText = string.Format("Count of Orders : {0}", e.Value);
    }

    public void Dispose() {
        Northwind?.Dispose();
    }
}
csharp
using System;
#nullable disable

namespace Grid.Northwind {
    public partial 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
using Microsoft.EntityFrameworkCore;
#nullable disable

namespace Grid.Northwind {
    public partial class NorthwindContext : DbContext {

        public NorthwindContext(DbContextOptions<NorthwindContext> options)
            : base(options) {
        }
        // ...
        public virtual DbSet<Invoice> Invoices { get; set; }
        // ...
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) {
            if(!optionsBuilder.IsConfigured) {
                optionsBuilder.UseSqlServer("Server=.\\sqlexpress;Database=Northwind;Integrated Security=true");
            }
        }
        // ...
        protected override void OnModelCreating(ModelBuilder modelBuilder) {
        // ...
            modelBuilder.Entity<Invoice>(entity => {
                entity.HasNoKey();
                entity.ToView("Invoices");
                entity.Property(e => e.Address).HasMaxLength(60);
                entity.Property(e => e.City).HasMaxLength(15);
                entity.Property(e => e.Country).HasMaxLength(15);
                entity.Property(e => e.CustomerId)
                    .HasMaxLength(5)
                    .HasColumnName("CustomerID")
                    .IsFixedLength(true);
                entity.Property(e => e.CustomerName)
                    .IsRequired()
                    .HasMaxLength(40);
                entity.Property(e => e.ExtendedPrice).HasColumnType("money");
                entity.Property(e => e.Freight).HasColumnType("money");
                entity.Property(e => e.OrderDate).HasColumnType("datetime");
                entity.Property(e => e.OrderId).HasColumnName("OrderID");
                entity.Property(e => e.PostalCode).HasMaxLength(10);
                entity.Property(e => e.ProductId).HasColumnName("ProductID");
                entity.Property(e => e.ProductName)
                    .IsRequired()
                    .HasMaxLength(40);
                entity.Property(e => e.Region).HasMaxLength(15);
                entity.Property(e => e.RequiredDate).HasColumnType("datetime");
                entity.Property(e => e.Salesperson)
                    .IsRequired()
                    .HasMaxLength(31);
                entity.Property(e => e.ShipAddress).HasMaxLength(60);
                entity.Property(e => e.ShipCity).HasMaxLength(15);
                entity.Property(e => e.ShipCountry).HasMaxLength(15);
                entity.Property(e => e.ShipName).HasMaxLength(40);
                entity.Property(e => e.ShipPostalCode).HasMaxLength(10);
                entity.Property(e => e.ShipRegion).HasMaxLength(15);
                entity.Property(e => e.ShippedDate).HasColumnType("datetime");
                entity.Property(e => e.ShipperName)
                    .IsRequired()
                    .HasMaxLength(40);
                entity.Property(e => e.UnitPrice).HasColumnType("money");
            });
            // ...
            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
csharp
using Microsoft.EntityFrameworkCore;
// ...
builder.Services.AddDbContextFactory<NorthwindContext>((sp, options) => {
    var env = sp.GetRequiredService<IWebHostEnvironment>();
    var dbPath = Path.Combine(env.ContentRootPath, "Northwind-5e44b51f.mdf");
    options.UseSqlServer("Server=(localdb)\\MSSQLLocalDB;Integrated Security=true;AttachDbFileName=" + dbPath);
});

For additional information about summaries in the Grid component, refer to the following topic: Summary in Blazor Grid.

Implements

GetGroupSummaryDisplayText(IGridSummaryItem, Int32)

See Also

DxGrid Class

DxGrid Members

DevExpress.Blazor Namespace