GridExportCustomizeCellEventArgs.DataItem Property
Returns the data source item that is bound to the data row being processed.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v25.1.dll
NuGet Package: DevExpress.Blazor
Declaration
public object DataItem { get; }
Property Value
| Type | Description |
|---|---|
| Object | If the processed cell belongs to a data row, the property returns a data item bound to this row. Otherwise, the property returns |
Remarks
Use the DataItem property to get the data source item that is bound to the data row being processed. If the current cell does not belong to a data row (the AreaType property returns a value other than DataArea), the DataItem property returns null.
Pass the DataItem property value to the GetDataItemValue method to get the item’s field value when the Grid is bound to one of the following data sources:
- An Instant Feedback Data Source whose AreSourceRowsThreadSafe option is set to
false(its default value) - A collection of anonymous objects
In other cases, you can cast the DataItem property value to the corresponding type and use the {DataItem.FieldName} notation to get the item’s field value.
The following code snippet adds hyperlinks to the exported grid cell values.
<DxGrid @ref="Grid" Data="@Data" PagerVisible="false" >
<Columns>
<DxGridDataColumn FieldName=@nameof(TestModel.Name) Width="280" >
<CellDisplayTemplate>
@context.Value
</CellDisplayTemplate>
</DxGridDataColumn>
<DxGridDataColumn FieldName=@nameof(TestModel.Universal) Width="100" />
<DxGridDataColumn FieldName=@nameof(TestModel.DXperience) Width="100" />
<DxGridDataColumn FieldName=@nameof(TestModel.WinForms) Width="100" />
<DxGridDataColumn FieldName=@nameof(TestModel.WPF) Width="100" />
<DxGridDataColumn FieldName=@nameof(TestModel.ASP) Caption= "ASP.NET and Blazor" Width="100" />
<DxGridDataColumn FieldName=@nameof(TestModel.DevExtreme) Caption="DevExtreme Complete" Width="100" />
</Columns>
<DataColumnCellDisplayTemplate>
@if((bool)context.Value == true) {
<span class="grid-icon grid-icon-check"></span>
}
</DataColumnCellDisplayTemplate>
</DxGrid>
<DxButton Text="Export to XLSX" Click="ExportXlsx_Click" />
@code {
object? Data { get; set; }
IGrid Grid { get; set; }
protected override async Task OnInitializedAsync() {
Data = await _testModelService.GetDataSourceAsync();
}
async Task ExportXlsx_Click() {
var options = new GridXlExportOptions();
options.CustomizeCell = (e) => {
if (e.AreaType == DevExpress.Export.SheetAreaType.DataArea && e.ColumnFieldName == "Name") {
var product = e.DataItem as TestModel;
e.Hyperlink = product.Url;
e.Handled = true;
}
};
await Grid.ExportToXlsxAsync("ExportResult", options);
}
}
