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

    Contains contextual information for a TreeList footer context menu.

    Namespace: DevExpress.Blazor

    Assembly: DevExpress.Blazor.v25.2.dll

    NuGet Package: DevExpress.Blazor

    Declaration

    public class TreeListFooterCommandContext :
        GridFooterCommandContextBase,
        ITreeListCommandContext,
        ICommandContextBase

    Remarks

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

    DevExpress Blazor TreeList - 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 TreeList element and obtain contextual information.

    Target Element Context Type Contextual information
    Any ITreeListCommandContext TreeList
    Data Row TreeListDataRowCommandContext TreeList, Column, DataItem, RowVisibleIndex
    Footer TreeListFooterCommandContext TreeList, Column, SummaryItems
    Header TreeListHeaderCommandContext TreeList, Column

    Example

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

    TreeList Context Menu - Add Total Summaries

    @inject EmployeeTaskService EmployeeTaskService
    
    <DxTreeList Data="TreeListData"
                PageSize="5"
                KeyFieldName="Id"
                ParentKeyFieldName="ParentId"
                FooterDisplayMode="TreeListFooterDisplayMode.Always"
                ContextMenus="TreeListContextMenus.Footer"
                CustomizeContextMenu="CustomizeContextMenu">
        <Columns>
            <DxTreeListSelectionColumn Width="80px" />
            <DxTreeListDataColumn FieldName="Name" Caption="Task" ShowInColumnChooser="false" />
            <DxTreeListDataColumn FieldName="EmployeeName" />
            <DxTreeListDataColumn FieldName="StartDate" />
            <DxTreeListDataColumn FieldName="DueDate" />
        </Columns>
        <TotalSummary>
            @foreach (var item in SummaryItems) {
                <DxTreeListSummaryItem FieldName="@item.FieldName"
                                       SummaryType="item.Type"
                                       ValueDisplayFormat="@item.DisplayFormat"
                                       @key="item" />
            }
        </TotalSummary>
    </DxTreeList>
    
    @code {
        List<EmployeeTask> TreeListData { get; set; }
    
        IList<SummaryItem> SummaryItems { get; set; }
        static readonly TreeListSummaryItemType[] SummaryTypes = Enum.GetValues<TreeListSummaryItemType>()
            .Where(s => s != TreeListSummaryItemType.None && s != TreeListSummaryItemType.Custom && s != TreeListSummaryItemType.Sum)
            .ToArray();
        bool IsStringColumn(string fieldName) => new[] { "Name", "EmployeeName" }.Contains(fieldName);
    
        record SummaryItem(string FieldName, TreeListSummaryItemType Type) {
            public string DisplayFormat { get; init; }
        }
    
        protected override void OnInitialized() {
            TreeListData = EmployeeTaskService.GenerateData();
            SummaryItems = new List<SummaryItem>([
                new SummaryItem("DueDate", TreeListSummaryItemType.Count),
            ]);
        }
        void CustomizeContextMenu(TreeListCustomizeContextMenuEventArgs args) {
            ITreeListColumn column = null;
            IReadOnlyList<ITreeListSummaryItem> contextSummaryItems = null;
            IList<SummaryItem> summaryItemsCollection = null;
    
            if (args.Context is TreeListFooterCommandContext footerCommandContext) {
                column = footerCommandContext.Column;
                contextSummaryItems = footerCommandContext.SummaryItems;
                summaryItemsCollection = SummaryItems;
            }
            if (column != null && column is ITreeListDataColumn dataColumn) {
                foreach (var summaryType in SummaryTypes) {
                    var fieldName = dataColumn.FieldName;
                    if (IsStringColumn(fieldName) && summaryType != TreeListSummaryItemType.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(ITreeListDataColumn dataColumn, TreeListSummaryItemType 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 == TreeListSummaryItemType.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
    TreeListFooterCommandContext
    See Also