Mewriick / Blazor.FlexGrid

GridView component for Blazor
MIT License
199 stars 35 forks source link

Question - blazor wasm and lazy loading #81

Closed dazinator closed 4 years ago

dazinator commented 4 years ago

Hello, I'm working on a blazor wasm (client side) project. I would like a lazy loaded grid. From one of the samples, it looks like you implement an ILazyDataSetLoader<TItem> and in there you return data from memory. I assume if I want to fetch data from a backend api, I need to implement an ILazyDataSetLoader<TItem> that makes Http calls to the backend to fetch the data. However then I got confused because I then saw this which seemed much less effort:

<GridView DataAdapter="@forecastAdapter"
          LazyLoadingOptions="@(new LazyLoadingOptions() {
                                    DataUri = "api/SampleData/WeatherForecasts",
                                    PutDataUri = "api/SampleData/UpdateWeatherForecast",
                                    DeleteUri = "api/SampleData/Delete/{Id}" })"

Some questions:

  1. When to implement ILazyDataSetLoader<TItem> versus just supplying LazyLoadingOptions with uri's as above?

  2. My http calls to backend api will need have a JWT token appended in header. How best to take control / supply the HttpClient that the grid view will use when making calls via the LazyLoadingOptions approach above?

Mewriick commented 4 years ago

Hi @dazinator

Ad 1) You implement ILazyDataSetLoader<TItem> only when you have some special scenarios. You also must this service register into the DI container after FlexGrid when you want to use it. Default behavior is implemented with HttpLazyDataSetLoader which makes Http calls with adresses provided by LazyLoadingOptions configuration object. So basically you can use this.

Ad 2) For those scenarios you can use UseAuthorizationForHttpRequests options for FLexGrid when you setup in DI container. After that you must create service which implemets IAuthorizationService interface and the Bearer token will be provided in every request see AuthorizationHttpClientFactory also you can create your own factory by implementig interface IHttpClientFactory

I hope that answers will help you!

dazinator commented 4 years ago

Thank you, I'll give that a go! Cheers