Hy,
I created a generic class for telerik grids to manage different data models.
In this class I use OnRead event for reading data :
protected async Task OnReadHandlerAsync(GridReadEventArgs args)
{
try
{
var query = Service.QueryDto();
query = DefaultFilterCondition is not null ? query.Where(DefaultFilterCondition) : query;
var dataSourceResult = await query.ToDataSourceResultAsync(args.Request);
if (args.Request.Aggregates.Any())
{
args.AggregateResults = dataSourceResult.AggregateResults;
}
args.Data = dataSourceResult.Data;
args.Total = dataSourceResult.Total;
}
catch (Exception ex)
{
NotificationService.Error(ex.Message);
}
}
As you can see I use the ToDataSourceResult extension on a variable of type IQueryable<TDto> for automatic sorting, filtering,paging,...
But now I have a problem: I created a grid that contains aggregates, now for this TelerikGrid the application throws the "must be reducible node exception" when the "ToDataSourceResult" is executed on the IQueyable<TDto> variable.
My TelerikGrid with aggregates:
@inherits GridReadOnlyComponentBase<SimulationResultService,SimulationResultDto>
<TelerikGrid Id="simulationresultgrid"
@ref="GridRef"
TItem="SimulationResultDto"
OnStateInit="@OnStateInitHandler"
FilterMode="@GridFilterMode.FilterRow"
EditMode="@GridEditMode.None"
SelectionMode="@GridSelectionMode.None"
Sortable="@true" SortMode="@SortMode.Single"
Groupable="@true" LoadGroupsOnDemand="@false"
Reorderable="@false"
OnRead="@OnReadHandlerAsync">
<GridAggregates>
<GridAggregate Field="@nameof(SimulationResultDto.ActualSales)" Aggregate="@GridAggregateType.Sum" FieldType="typeof(decimal)" />
<GridAggregate Field="@nameof(SimulationResultDto.YearImpact)" Aggregate="@GridAggregateType.Sum" FieldType="typeof(decimal)" />
<GridAggregate Field="@nameof(SimulationResultDto.ChangesImpact)" Aggregate="@GridAggregateType.Sum" FieldType="typeof(decimal)" />
</GridAggregates>
<NoDataTemplate>
<strong>@(_simulationId > 0 ? "Nessun dato presente,eseguire prima una simulazione" : "Scegli la simulazione")</strong>
</NoDataTemplate>
<GridToolBarTemplate>
<span class="k-toolbar-spacer" />
<SimulationSelect SelectedValue="_simulationId" SelectedValueChanged="SimulationIdChanged" Width="30%" />
</GridToolBarTemplate>
<GridColumns>
<GridColumn Field="@nameof(SimulationResultDto.ActualSales)"
Title="Fat. attuale"
Width="200px" DisplayFormat="{0:C}"
Filterable="false"
Groupable="false">
<GroupFooterTemplate>
TOT: <TelerikNumericTextBox Width="80%" ReadOnly="@true" Arrows="@false" Decimals="2" Format="C" @bind-Value="@context.Sum" />
</GroupFooterTemplate>
</GridColumn>
</GridColumns>
I know that a solution could be to run the ToList before running the ToDataSourceResult but I would like to know if there is another solution as I work with a large amount of data.
Thanks