Answer:
The CustomAdaptor as a Component feature can be used. Here is the
UG documentation for your reference.
In the below code snippet where CustomAdaptor is a Component. The ID value is passed as a parameter to CustomAdaptor component using the value required operation can be performed.
[OrderDetailsComponent.razor]
<p>Data for @Idp>
<SfGrid TValue="OrderItem" Toolbar="@(new List<string>()
{ "Add", "Edit", "Delete", "Update", "Cancel" })"
AllowPaging="true">
. . .
@*
Adaptor="Adaptors.CustomAdaptor">
*@
<SfDataManager Adaptor="Adaptors.CustomAdaptor">
<CustomAdaptorComponent Id="@Id">CustomAdaptorComponent> //passed Id value as a parameter
in CustomAdaptorComponent
SfDataManager>
<GridColumns>
. . .
GridColumns>
SfGrid> |
Here, the custom adaptor codes from OrderDetailsComponent.razor.cs moved to CustomAdaptorComponent.razor file. While rendering the Grid ReadAsync method will be called from CustomAdaptorComponent.razor file.
[CustomAdaptorComponent.razor]
. . .
@inherits DataAdaptor
<CascadingValue Value="@this">
@ChildContent
CascadingValue>
@code {
[Parameter]
[JsonIgnore]
public RenderFragment ChildContent { get; set; }
[Parameter]
public int Id { get; set; }
[Inject]
public IOrderItemService context { get; set; }
public override async Task<object> ReadAsync(DataManagerRequest dataManagerRequest, string key = null)
{
await Task.Yield();
IEnumerable GridData = await context.OrderItemsByOrderId(Id);
. . .
return dataManagerRequest.RequiresCounts ? new DataResult() { Result = GridData, Count
= count } : (object)GridData;
}
. . .
} |