Back to Devexpress

GridExportOptions.RowExporting Property

blazor-devexpress-dot-blazor-dot-gridexportoptions-a5a7d3db.md

latest4.5 KB
Original Source

GridExportOptions.RowExporting Property

Fires before a row is exported and allows you to cancel the action.

Namespace : DevExpress.Blazor

Assembly : DevExpress.Blazor.v25.2.dll

NuGet Package : DevExpress.Blazor

Declaration

csharp
public Action<GridRowExportingEventArgs> RowExporting { get; set; }

Property Value

TypeDescription
Action<GridRowExportingEventArgs>

A delegate method that specifies whether the row export should be canceled.

|

Remarks

Write the RowExporting delegate action handler to filter the exported grid data.

View Example: Customize Export Settings

The Grid calls the RowExporting action for data and group rows. Use the IsGroupRow property to determine the type of the row currently being processed.

The following event argument properties allow you to get information about the processed row.

DataItemFor data rows only. Returns a data source item that corresponds to the row or null if a group row is being processed.GroupFieldNameFor group rows only. Returns the name of a data source field that is bound to the processed group column or null if a data row is being processed.GetRowValue(String)Returns the value of the specified data field in the current row. If a group row is processed, send the GroupFieldName property value to the GetRowValue method to get the row value.

Set the Cancel property to true to exclude the row from the exported document.

Note

If you exclude a group row from the exported document, you should also cancel the export of all data rows in that group. Otherwise, the data hierarchy in the resulting document breaks.

For additional information about data export in the Grid component, refer to the following topic: Export Data in Blazor Grid.

Example

The following code snippet exports rows that contain values larger than 1000 in the Total column.

razor
<DxGrid @ref="Grid" Data="@Data" >
    <Columns>
        <DxGridDataColumn FieldName="CompanyName" />
        <DxGridDataColumn FieldName="Country" />
        <DxGridDataColumn FieldName="UnitPrice" DisplayFormat="c" />
        <DxGridDataColumn FieldName="Quantity" />
        <DxGridDataColumn FieldName="Total" UnboundType="GridUnboundColumnType.Integer" 
                          DisplayFormat="c" UnboundExpression="[UnitPrice]*[Quantity]" />
    </Columns>
</DxGrid>
<DxButton Text="Export Big Deals to XLSX" Click="ExportXlsx_Click" />
@code {
    object Data { get; set; }
    IGrid Grid { get; set; }
    protected override async Task OnInitializedAsync() {
        var invoices = await NwindDataService.GetInvoicesAsync();
        var customers = await NwindDataService.GetCustomersAsync();
        Data = invoices.OrderBy(i => i.OrderDate).Join(customers, i => i.CustomerId, c => c.CustomerId, (i, c) => {
            return new {
                OrderDate = i.OrderDate,
                CompanyName = c.CompanyName,
                City = i.City,
                Region = i.Region,
                Country = i.Country,
                UnitPrice = i.UnitPrice,
                Quantity = i.Quantity
            };
        });
    }
    async Task ExportXlsx_Click() {
        var options = new GridXlExportOptions();
        // Exports rows with Total value larger than 1000
        options.RowExporting = e => {
            if (!e.IsGroupRow) {
                if ((int)e.GetRowValue("Total") < 1000) {
                    e.Cancel = true;
                }
            }
        };
       await Grid.ExportToXlsxAsync("Big Deals", options);
    }
}

See Also

GridExportOptions Class

GridExportOptions Members

DevExpress.Blazor Namespace