GridDocumentExportCustomizeCellEventArgsBase.DataItem Property
Returns the data item bound to the processed data row.
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 the data item bound to this row. Otherwise, the property returns |
Remarks
When exporting Grid/TreeList data to PDF, handle the CustomizeCell
event to customize table cells in the output file. Use the DataItem
event argument to obtain the item bound to the processed data row. This argument returns null
if the cell does not belong to a data row (the AreaType argument returns a value other than DataArea
).
Pass the DataItem
to the GetDataItemValue
method to get the item’s field value when the component is bound to one of the following data sources:
- A collection of anonymous objects
- An Instant Feedback Data Source whose AreSourceRowsThreadSafe option is set to
false
(its default value)
In other cases, you can cast the DataItem
to the corresponding type and use the {DataItem.FieldName}
notation to get the item’s field value.
Grid Example
The following example exports Grid data to PDF and customizes the output table appearance:
@rendermode InteractiveServer
@using DevExpress.Drawing;
@inject WeatherForecastService ForecastService
<DxGrid @ref="Grid" Data="@forecasts" ShowGroupPanel="true">
<Columns>
<DxGridDataColumn Caption="Date" FieldName="Date" />
<DxGridDataColumn Caption="Temperature (C)" FieldName="TemperatureC" ExportWidth="300"/>
<DxGridDataColumn Caption="Temperature (F)" FieldName="TemperatureF" ExportWidth="300" />
<DxGridDataColumn Caption="Summary" FieldName="Summary" GroupIndex="0" />
</Columns>
<TotalSummary>
<DxGridSummaryItem SummaryType="GridSummaryItemType.Count" FieldName="Date" />
<DxGridSummaryItem SummaryType="GridSummaryItemType.Min" FieldName="TemperatureC" />
<DxGridSummaryItem SummaryType="GridSummaryItemType.Max" FieldName="TemperatureC" />
</TotalSummary>
<ToolbarTemplate>
<DxToolbar>
<DxToolbarItem Text="Export to PDF" Click="ExportPdf_Click" BeginGroup="true" />
</DxToolbar>
</ToolbarTemplate>
</DxGrid>
@code {
IGrid Grid;
private WeatherForecast[]? forecasts;
protected override async Task OnInitializedAsync() {
forecasts = await ForecastService.GetForecastAsync(DateOnly.FromDateTime(DateTime.Now));
}
async Task ExportPdf_Click() {
await Grid.ExportToPdfAsync("ExportResult", new GridPdfExportOptions() {
CustomizeCell = OnCustomizeCell,
});
}
void OnCustomizeCell(GridDocumentExportCustomizeCellEventArgs args) {
if (args.AreaType == DocumentExportAreaType.Header){
args.ElementStyle.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
args.ElementStyle.Font = new DXFont("Arial", 10, DXFontStyle.Bold);
}
if (args.AreaType == DocumentExportAreaType.GroupHeader && args.GroupFieldName == "Summary")
args.Text = args.Value + ":";
if (args.AreaType == DocumentExportAreaType.DataArea) {
args.ElementStyle.BackColor = System.Drawing.Color.MintCream;
if (args.ColumnFieldName.Contains("Temperature")) {
var forecast = (WeatherForecast)args.DataItem;
if (forecast.TemperatureC < 0)
args.ElementStyle.ForeColor = System.Drawing.Color.Blue;
if (forecast.TemperatureC > 30)
args.ElementStyle.ForeColor = System.Drawing.Color.Red;
}
}
if (args.AreaType == DocumentExportAreaType.TotalFooter && args.ColumnFieldName == "TemperatureC") {
args.Text = args.SummaryItems[0].Text + "°C\n" + args.SummaryItems[1].Text + "°C";
args.ElementStyle.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleRight;
}
args.Handled = true;
}
}
TreeList Example
The following example exports TreeList data to PDF and customizes the output table appearance:
@rendermode InteractiveServer
@using DevExpress.Drawing
@inject SpaceObjectDataProvider SpaceObjectDataProvider
<DxTreeList @ref="TreeList" Data="TreeListData" ChildrenFieldName="Satellites">
<Columns>
<DxTreeListDataColumn FieldName="Name" />
<DxTreeListDataColumn FieldName="TypeOfObject" Caption="Type" />
<DxTreeListDataColumn FieldName="Mass10pow21kg" Caption="Mass, kg" DisplayFormat="N2" />
<DxTreeListDataColumn FieldName="MeanRadiusInKM" Caption="Radius, km" DisplayFormat="N2" />
</Columns>
<TotalSummary>
<DxTreeListSummaryItem SummaryType="TreeListSummaryItemType.Count" FieldName="Name" />
<DxTreeListSummaryItem SummaryType="TreeListSummaryItemType.Min" FieldName="MeanRadiusInKM" />
<DxTreeListSummaryItem SummaryType="TreeListSummaryItemType.Max" FieldName="MeanRadiusInKM" />
</TotalSummary>
<ToolbarTemplate>
<DxToolbar>
<DxToolbarItem Text="Export to PDF" Click="ExportPdf_Click" BeginGroup="true" />
</DxToolbar>
</ToolbarTemplate>
</DxTreeList>
@code {
ITreeList TreeList { get; set; }
object TreeListData { get; set; }
protected override async Task OnInitializedAsync() {
TreeListData = SpaceObjectDataProvider.GenerateData();
}
async Task ExportPdf_Click() {
await TreeList.ExportToPdfAsync("ExportResult", new TreeListPdfExportOptions() {
CustomizeCell = OnCustomizeCell,
});
}
void OnCustomizeCell(TreeListDocumentExportCustomizeCellEventArgs args) {
if (args.AreaType == DocumentExportAreaType.Header) {
args.ElementStyle.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
args.ElementStyle.Font = new DXFont("Arial", 10, DXFontStyle.Bold);
}
if (args.AreaType == DocumentExportAreaType.DataArea) {
var spaceObject = (SpaceObject)args.DataItem;
if (spaceObject.TypeOfObject == "Planet")
args.ElementStyle.BackColor = System.Drawing.Color.LightBlue;
if (args.ColumnFieldName == "Mass10pow21kg" && (double)args.Value > 10)
args.ElementStyle.Font = new DXFont(args.ElementStyle.Font, DXFontStyle.Bold);
}
if (args.AreaType == DocumentExportAreaType.TotalFooter && args.ColumnFieldName == "MeanRadiusInKM") {
args.Text = args.SummaryItems[0].Text + " km\n" + args.SummaryItems[1].Text + "km";
args.ElementStyle.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleRight;
}
args.Handled = true;
}
}