<EjsDataManager @ref="@defaultDataManager" AdaptorInstance="@typeof(CustomAdaptor)" Adaptor="Adaptors.CustomAdaptor"></EjsDataManager>Currently there is no way to set the dataManager instance manually e.g. in the OnAfterRenderAsync method.
Is there any other way to perform this?Hello Vignesh,
based on your example above i'm wondering is there a way to achieve a build a CustomAdaptorComponent with a parameter for a Service. Sort of <CustomAdaptor Service"@OrderService"></CustomAdaptor>? or maybe a kind of a generic CustomerAdaptor.
In my project business layer there are a lot of service classes that inherits from a generic service class. if i understand it right, i have now to build for all these service classes a separate adaptor component with lots of redundant code.
So what i need is one CustomAdaptor that operates with every of my services.
What is the best practice to do that?
Regards
Stefan
|
[Index.razor]
<SfGrid TValue="Order" AllowPaging="true" EnableHover="false" AllowSorting="true">
<GridPageSettings PageSize="5"></GridPageSettings>
<SfDataManager Adaptor="Adaptors.CustomAdaptor">
<CustomComponent T="Order" Details="Orders"></CustomComponent>
</SfDataManager>
<GridColumns>
….
</GridColumns>
</SfGrid>
[Test1.Razor]
|
|
|
<SfGrid TValue="Order"AllowPaging="true" EnableHover="false" AllowSorting="true">
[CustomComponent.Razor]
@typeparam T where T : class, IDataModel, new()
@typeparam U where U : IGenericService<T>
@inherits DataAdaptor<U>
<CascadingValue Value="@this"> @ChildContent</CascadingValue>
@code {
[Parameter]
[JsonIgnore]
public RenderFragment ChildContent { get; set; }
[Parameter]
public List<T> Details { get; set; }
// Performs data Read operation
public override object Read(DataManagerRequest dm, string key = null)
{ ... }
public override async Task<object> ReadAsync(DataManagerRequest dm, string key = null)
{
var data = await Service.GetListAsync();
IEnumerable<T> DataSource = (IEnumerable<T>)data;
if (dm.Search != null && dm.Search.Count > 0)
{ ....
[OrdersDataService]
...
public virtual async Task<IEnumerable<T>> GetListAsync()
{
var bearer = (await _protectedLocalStorage.GetAsync<string>("BearerToken")).Value ?? string.Empty;
...set Authorization Header in HttpClient and fire request an so on
}
If i now open Index.razor the ReadAsync Method is firing the GetListAsync Method of th DataService and its running to an error as its try to get the values from ProtectedLocalStorage
[ERROR]
JavaScript interop calls cannot be issued at this time. This is because the component is being statically rendered. When prerendering is enabled, JavaScript interop calls can only be performed during the OnAfterRenderAsync lifecycle method.
FYI: _Host render-mode = "Server"
I know the problem is probably at ProtectedLocalStorage, because the Reader tries to get data before Rendering but i don't think i'm the first with this approach. Either i have to delay the Reading method or i have to store the user data elsewhere. Do you have any suggestions?
Regards
Stefan
Hi
Its me again, after some researching and testing, i found a solution. Maybe i thought to much around the corner.
I' using now
[CustomComponent.Razor]
@inherits DataAdaptor
[Parameter] public IGenericService<T> MyDataService { get; set; }
instead of
@typeparam U where U : IGenericService<T>
@inherits DataAdaptor<U>
and replaced all service calls in all overrided methods
//var data = await Service.GetListAsync();
var data = await MyDataService.GetListAsync();
and voilá the cookie crumbles :-)
Regards
Stefan
Hi Stefan,
Thanks for the update.
We are happy to hear that you have found the solution for your case. Please get back to us if you need further assistance.
Regards,
Rahul