Skip to main content

GridDevExtremeDataSource<T>.CustomizeLoadOptions Property

Customizes load options before the grid loads data.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v23.2.dll

NuGet Package: DevExpress.Blazor

Declaration

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 code below 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://docs.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