Skip to main content
All docs
V25.2
  • GridFooterCommandContext Class

    Contains contextual information for a Grid footer context menu.

    Namespace: DevExpress.Blazor

    Assembly: DevExpress.Blazor.v25.2.dll

    Declaration

    public class GridFooterCommandContext :
        GridFooterCommandContextBase,
        IGridCommandContext,
        ICommandContextBase

    Remarks

    The DevExpress Blazor Grid allows you to display context menus with predefined and custom commands. Use the ContextMenus property to activate context menus for specific Grid elements.

    DevExpress Blazor Grid - Context Menus

    Run Demo: Context Menu

    Handle the CustomizeContextMenu event to modify the menu item collection. Use the Context event argument to identify the target Grid element and obtain contextual information.

    Target Element Context Type Contextual information
    Any GridCommandContext Grid
    Data Row GridDataRowCommandContext Grid, Column, DataItem, RowVisibleIndex
    Footer GridFooterCommandContext Grid, Column, SummaryItems
    Group Footer GridGroupFooterCommandContext Grid, Column, GroupRowVisibleIndex, SummaryItems
    Group Panel GridGroupPanelCommandContext Grid
    Group Row GridGroupRowCommandContext Grid, GroupColumn, RowVisibleIndex
    Header GridHeaderCommandContext Grid, Column

    Example

    The following example adds context commands that display/hide total summaries:

    Grid Context Menu - Add Total Summaries

    @inject WeatherForecastService ForecastService
    
    <DxGrid Data="@forecasts"
            PageSize="5" 
            FooterDisplayMode="GridFooterDisplayMode.Always"
            ContextMenus="GridContextMenus.Footer"
            CustomizeContextMenu="OnCustomizeContextMenu">
        <Columns>
            <DxGridSelectionColumn />
            <DxGridDataColumn FieldName=@nameof(WeatherForecast.TemperatureC) Caption="Temp. (C)" />
            <DxGridDataColumn FieldName=@nameof(WeatherForecast.TemperatureF) Caption="Temp. (F)" />
            <DxGridDataColumn FieldName=@nameof(WeatherForecast.Summary) Caption="Summary" />
            <DxGridDataColumn FieldName=@nameof(WeatherForecast.Date) DisplayFormat="dd/MM/yyyy" />
        </Columns>
        <TotalSummary>
            @foreach (var item in SummaryItems) {
                <DxGridSummaryItem FieldName="@item.FieldName"
                                   SummaryType="item.Type"
                                   ValueDisplayFormat="@item.DisplayFormat"
                                   @key="item" />
            }
        </TotalSummary>
    </DxGrid>
    
    @code {
        string[]? summaries;
        private List<WeatherForecast>? forecasts;
    
        IList<SummaryItem> SummaryItems { get; set; }
        static readonly GridSummaryItemType[] SummaryTypes = Enum.GetValues<GridSummaryItemType>()
            .Where(s => s != GridSummaryItemType.None && s != GridSummaryItemType.Custom && s != GridSummaryItemType.Sum)
            .ToArray();
        bool IsStringColumn(string fieldName) => new[] { "Summary" }.Contains(fieldName);
    
        record SummaryItem(string FieldName, GridSummaryItemType Type) {
            public string DisplayFormat { get; init; }
        }
    
        protected override async Task OnInitializedAsync() {
            forecasts = await ForecastService.GetForecastAsync();
            summaries = ForecastService.Summaries;
            SummaryItems = new List<SummaryItem>([
                new SummaryItem("TemperatureC", GridSummaryItemType.Count),
            ]);
        }
    
        void OnCustomizeContextMenu(GridCustomizeContextMenuEventArgs args) {
            IGridColumn column = null;
            IReadOnlyList<IGridSummaryItem> contextSummaryItems = null;
            IList<SummaryItem> summaryItemsCollection = null;
    
            if (args.Context is GridFooterCommandContext footerCommandContext) {
                column = footerCommandContext.Column;
                contextSummaryItems = footerCommandContext.SummaryItems;
                summaryItemsCollection = SummaryItems;
            }
            if (column != null && column is IGridDataColumn dataColumn) {
                foreach (var summaryType in SummaryTypes) {
                    var fieldName = dataColumn.FieldName;
                    if (IsStringColumn(fieldName) && summaryType != GridSummaryItemType.Count)
                        continue;
                    var existingItem = contextSummaryItems.FirstOrDefault(i => i.FieldName == fieldName && i.SummaryType == summaryType);
                    var menuItem = args.Items.AddCustomItem(summaryType.ToString(), () => OnSummaryCommand(dataColumn, summaryType, summaryItemsCollection));
                }
            }
        }
    
        void OnSummaryCommand(IGridDataColumn dataColumn, GridSummaryItemType summaryType, IList<SummaryItem> summaryItemsCollection) {
            var fieldName = dataColumn.FieldName;
            var existingItem = summaryItemsCollection.FirstOrDefault(i => i.FieldName == fieldName && i.Type == summaryType);
            if (existingItem != null)
                summaryItemsCollection.Remove(existingItem);
            else
                summaryItemsCollection.Add(new SummaryItem(fieldName, summaryType) {
                        DisplayFormat = summaryType == GridSummaryItemType.Count ? null : dataColumn.DisplayFormat
                    });
            StateHasChanged();
        }
    }
    

    Run Demo: Context Menu

    Inheritance

    Object
    DevExpress.Blazor.Grid.Internal.Base.ContextMenu.GridCommandContextBase
    DevExpress.Blazor.Grid.Internal.Base.ContextMenu.GridHeaderCommandContextBase
    DevExpress.Blazor.Grid.Internal.Base.ContextMenu.GridFooterCommandContextBase
    GridFooterCommandContext
    See Also