Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

GridDevExtremeDataSource<T>.CustomizeLoadOptions Property

Customizes load options before the grid loads data.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

#Declaration

C#
public Action<DataSourceLoadOptionsBase> CustomizeLoadOptions { get; set; }

#Property Value

Type Description
Action<DevExtreme.AspNet.Data.DataSourceLoadOptionsBase>

A delegate method that configures load options.

#Remarks

If underlying data is a large SQL table, you can customize load options to get a more efficient SQL execution plan. Pass a DataSourceLoadOptionsBase object to the CustomizeLoadOptions property and specify object properties.

The following code snippet specifies the PrimaryKey and PaginateViaPrimaryKey properties for a data source.

@inherits OwningComponentBase
@inject Microsoft.Extensions.Configuration.IConfiguration Configuration
<DxGrid Data="@Data" PageSize="10">
    <Columns>
        <DxGridDataColumn FieldName="State" Width="5%" />
        <DxGridDataColumn FieldName="Area" MinWidth="100" />
        <DxGridDataColumn FieldName="City" Caption="County" MinWidth="100" />
        <DxGridDataColumn FieldName="Name" Caption="Location" MinWidth="100" />
        <DxGridDataColumn FieldName="Year" DisplayFormat="0" Width="10%" />
        <DxGridDataColumn FieldName="Bedrooms" Width="10%" />
        <DxGridDataColumn FieldName="Population" DisplayFormat="#,0" MinWidth="80" Width="10%" />
    </Columns>
</DxGrid>

@code {
    IRentInfoDataProvider RentInfoDataProvider { get; set; }
    RentInfoDataService RentInfoDataService { get; set; }
    object Data { get; set; }
    protected override void OnInitialized() {
        // Refer to https://learn.microsoft.com/dotnet/api/microsoft.aspnetcore.components.owningcomponentbase
        RentInfoDataProvider = ScopedServices.GetRequiredService<IRentInfoDataProvider>();
        RentInfoDataService = ScopedServices.GetRequiredService<RentInfoDataService>();
        var connectionString = ConnectionStringUtils.GetGridLargeDataConnectionString(Configuration);
        if(string.IsNullOrEmpty(connectionString)) return;
        var dataSource = new GridDevExtremeDataSource<AreaRentInfo>(RentInfoDataService.GetAreaRentInfo());
        dataSource.CustomizeLoadOptions = (loadOptions) => {
            // If underlying data is a large SQL table, specify PrimaryKey and PaginateViaPrimaryKey.
            // This can make SQL execution plans more efficient.
            loadOptions.PrimaryKey = new[] { "Oid" };
            loadOptions.PaginateViaPrimaryKey = true;
        };
        Data = dataSource;
    }
}

Run Demo: Grid — Large Data (Queryable)

See Also