-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataAsyncProperty.Cache.razor
34 lines (28 loc) · 1.44 KB
/
DataAsyncProperty.Cache.razor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
@page "/DataAsyncUsingCache"
@inject WeatherForecastService WeatherForecastService
<h2>DataAsync: Cache Data</h2>
<p>
This example uses the <a class="helplink" href="https://docs.devexpress.com/Blazor/DevExpress.Blazor.DxDataGrid-1.DataAsync" target="_blank">DataAsync</a> property to bind the Data Grid to a strongly typed collection that is loaded asynchronously. The <b>DataAsync</b> function can be called multiple times during the grid's life cycle because Blazor can re-render components. This example demonstrates how to cache this function if it is time- or resource-consuming.
</p>
<p>
Note that the <b>Render GUID</b> does not change during page initialization. This means the page is rendered only once.
</p>
<p>
<b>Render GUID</b>: @Guid.NewGuid()
</p>
<DxDataGrid DataAsync="@LoadDataAsync" KeyFieldName="Id">
<Columns>
<DxDataGridColumn Field="@nameof(WeatherForecast.Summary)" />
<DxDataGridDateEditColumn Field="@nameof(WeatherForecast.Date)" />
<DxDataGridSpinEditColumn Field="@nameof(WeatherForecast.TemperatureC)" />
<DxDataGridSpinEditColumn Field="@nameof(WeatherForecast.TemperatureF)" />
</Columns>
</DxDataGrid>
@code {
IEnumerable<WeatherForecast> Cache;
async Task<IEnumerable<WeatherForecast>> LoadDataAsync(CancellationToken token) {
if (Cache == null)
Cache = await WeatherForecastService.GetForecastAsync(DateTime.Now.Date);
return Cache;
}
}