We have data coming from an API endpoint that handles paging, filtering, and sorting, so we are using manual data source operations through OnRead.
All of the documentation examples show this pattern
protected async Task OnRead(GridReadEventArgs args)
{
var result = await FetchData(args.Request.Page, args.Request.PageSize);
args.Data = result.Data;
args.Total = result.TotalCount;
}
This is not a usable pattern for us. We dispatch api calls using a Redux/Flux pattern (Fluxor library). Here is a trimmed down version of what we are doing
<TelerikGrid @* Data=CaseState.Value.Cases // since 3.x does nothing if using OnRead *@
@* TotalCount=CaseState.Value.TotalCount // not available since 3.x*@
PageSize=100
Pageable=true
Sortable=true
Resizable=true
Reorderable=true
OnRead=@OnRead
Width="100%"
@ref=_grid>
<GridColumns>
...
</GridColumns>
</TelerikGrid>
Code behind:
...
[Inject]
private IState<CaseState> CaseState { get; set; } = default!;
...
protected void OnRead(GridReadEventArgs args)
{
var pageRequest = CreateRequestFromArgs(args);
// This is a void method and returns immediately
Dispatcher.Dispatch(new GetCaseListAction() { SearchRequest = pageRequest });
}
When the api call returns (handled elsewhere) another action is dispatched to the store which updates the CaseState (which in turn triggers StateHasChanged() for the component).
Prior to 3.x we used to be able to pass the collection to the Data parameter AND make use of OnRead. This is no longer possible and results in a NullReferenceException because the Data is not being set on the GridReadEventArgs.
I looked at using GridState as it contains some of paging, filtering, and sorting info, but not the Total Count or the actual data. Is there a way to pass Data, TotalCount and the rest of the state in one place either declaratively through component parameters or programmatically via a component ref?