Skip to main content
All docs
V26.1
  • TreeListUnboundColumnDataEventArgs.DataItem Property

    Returns the processed data item.

    Namespace: DevExpress.Blazor

    Assembly: DevExpress.Blazor.Grid.v26.1.dll

    Declaration

    public object DataItem { get; }

    Property Value

    Type Description
    Object

    A data item.

    Remarks

    Handle the UnboundColumnData event to populate unbound columns with data. Use the DataItem event argument to obtain the processed record. Cast the record to the corresponding type and use the {DataItem.FieldName} notation to obtain the item’s field value.

    Note

    Use the GetRowValue method instead of the DataItem property to obtain a field value when the TreeList is bound to a collection of anonymous objects.

    Example

    The following code snippet creates two unbound columns:

    @inject ISalesByRegionDataProvider SalesByRegionDataProvider
    
    <DxTreeList Data="TreeListData"
                KeyFieldName="ID"
                ParentKeyFieldName="RegionID"
                ShowAllRows="true"
                ColumnResizeMode="TreeListColumnResizeMode.NextColumn"
                TextWrapEnabled="false"
                SizeMode="Params.SizeMode"
                CssClass="max-h-480"
                UnboundColumnData="TreeList_UnboundColumnData">
        <Columns>
            <DxTreeListDataColumn FieldName="Region" />
            <DxTreeListDataColumn FieldName="AprilSales" DisplayFormat="c0" />
            <DxTreeListDataColumn FieldName="MaySales" DisplayFormat="c0" />
            <DxTreeListDataColumn FieldName="JuneSales" DisplayFormat="c0" />
            <DxTreeListDataColumn FieldName="Q2Sales"
                                  Caption="Q2 Sales"
                                  DisplayFormat="c0"
                                  UnboundType="TreeListUnboundColumnType.Decimal"
                                  UnboundExpression="[AprilSales] + [MaySales] + [JuneSales]" />
            <DxTreeListDataColumn FieldName="Q2YoYChange"
                                  Caption="Q2 YoY Change (%)"
                                  DisplayFormat="p0"
                                  UnboundType="TreeListUnboundColumnType.Decimal" />
        </Columns>
    </DxTreeList>
    
    @code {
        object TreeListData { get; set; }
    
        protected override void OnInitialized() {
            TreeListData = SalesByRegionDataProvider.GenerateData();
        }
    
        void TreeList_UnboundColumnData(TreeListUnboundColumnDataEventArgs e) {
            if(e.FieldName == "Q2YoYChange") {
                var sales = ((SalesByRegion) e.DataItem);
                var currentValue = (decimal)e.GetRowValue("Q2Sales");
                var prevValue = sales.MonthlySalesPrev[3] + sales.MonthlySalesPrev[4] + sales.MonthlySalesPrev[5];
                e.Value = (currentValue - prevValue) / currentValue;
            }
        }
    }
    

    DevExpress Blazor TreeList - Unbound Columns

    Run Demo: Unbound Columns

    See Also