I have retrieved the claim I want to use for the key in the custom adapter. I've added @Entity to the HTML and there is the value I want on the page but the key param is null when it issues the ReadAsync
@code{
private string Entity { get; set; } = string.Empty;
private AuthenticationState? authState;
protected override async Task OnInitializedAsync()
{
authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
if (string.IsNullOrEmpty(Entity))
{
Entity = authState?.User?.Claims?.FirstOrDefault(x => x.Type == "Entity")?.Value??string.Empty;
}
}
public class CustomAdaptor : DataAdaptor
{
public string Entity;
public TimeData TimeService = new TimeData();
public override async Task<object> ReadAsync(DataManagerRequest DataManagerRequest, string Key = null)
{
IEnumerable<TimeEntry> DataSource = await TimeService.GetTimeAsync(Key);
}
}
}
This is the beginning of my grid section of the page
@Entity
<SfGrid TValue="TimeEntry" AllowSorting="true" AllowFiltering="true" AllowGrouping="true"
AllowPaging="true" Toolbar=@Toolbaritems
RowHeight="25">
<SfDataManager AdaptorInstance="@typeof(CustomAdaptor)" Adaptor="Adaptors.CustomAdaptor" Key="@Entity" ></SfDataManager>
Hi Following up on this
Hi
Lonny Blank,
We have reviewed your query and it seems that you need to pass the key
parameter in the CustomAdapter's ReadAsync method. You can send additional
parameters with the data request by using the AddParams method of the Query
class. We have already documented this in the following user guide section.
Kindly refer to the attached documentation for more details
Reference:
https://blazor.syncfusion.com/documentation/datagrid/custom-binding#how-to-pass-additional-parameters-to-custom-adaptor
Regards,
Naveen
What is the key argument used for. And how do I access it?
public override async Task<object> ReadAsync(DataManagerRequest DataManagerRequest, string Key = null)
Hi Lonny Blank,
We have considered it as a bug and logged an issue “Unable to Retrieve the Key Value from the SfDataManager in the Read Method's Additional Parameter” for the same. Thank you for taking the time to report this issue and helping us to improve our product. At Syncfusion, we are committed to fix all validated defects (subject to technological feasibility and Product Development Life Cycle) and this fix will be included in any of our upcoming patch release which is excepted to be rolled out on or before 12th November 2024.
You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link.
https://www.syncfusion.com/feedback/62504/unable-to-retrieve-the-key-value-from-the-sfdatamanager-in-the-read-methods
Disclaimer: “Inclusion of this solution in the weekly release may
change due to other factors including but not limited to QA checks and works
reprioritization”
Until then we appreciate your patience.
Regards,
Naveen
Thanks for your patience,
We are glad to announce that, we have included the fix for the issue “Unable to Retrieve the Key Value from the SfDataManager in the Read Method's Additional Parameter” in our Volume 3 SP 27.2.2 release. So please upgrade to our latest version of Syncfusion NuGet package to resolve the reported issue. Please find the NuGet package for the latest fixes and features below.
NuGet: https://www.nuget.org/packages/Syncfusion.Blazor.Grid
Release Notes:Essential
Studio for Blazor 2024 Volume 3 SP Release Release Notes
Root Cause: This issue occurs because while invoking read method
at the sample level DataManagerRequest only passed, so the additional paramater
pass the null value for key.
Corrective Actions Taken: To resolve the issue, check the
conditional statement where the additionalParam =
string.IsNullOrEmpty(additionalParam) &&
!string.IsNullOrEmpty(DataManagerInstance?.Key) ? DataManagerInstance?.Key :
additionalParam; and pass the key value
We thank you for your support and appreciate your patience in waiting for this
release.
How do I set the key value so it can be passed to the custom adaptor
Based on your requirement, you can use the Key property in the SfDataManager to pass the key value. You can then retrieve the key value in the ReadAsync method of the custom adapter. Kindly refer to the code snippet and sample below for your reference.
|
<SfGrid TValue="Order" ID="Grid" AllowFiltering="true" AllowPaging="true"> <SfDataManager AdaptorInstance="@typeof(CustomAdaptor)" Adaptor="Syncfusion.Blazor.Adaptors.CustomAdaptor" Key="1001"></SfDataManager> <GridPageSettings PageSize="8"></GridPageSettings> <GridColumns> <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="@Syncfusion.Blazor.Grids.TextAlign.Center" Width="140"></GridColumn> <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn> <GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" Width="150"></GridColumn> </GridColumns> </SfGrid>
@code {
// Implementing custom adaptor by extending the DataAdaptor class public class CustomAdaptor : DataAdaptor { // Performs data Read operation public override object Read(DataManagerRequest dm, string key ) {
|
Can the key be reset once data is passed to the grid?
Hi
Lonny,
We reviewed your query, and it appears that you want to reset the key
dynamically after passing the data to the grid. You can achieve this by using a
button to reset the key once the data is assigned to the grid. Please refer to
the provided code snippet and sample for more details.
|
<SfButton OnClick="click">reset</SfButton>
<SfGrid TValue="Order" ID="Grid" AllowFiltering="true" AllowPaging="true"> <SfDataManager AdaptorInstance="@typeof(CustomAdaptor)" Adaptor="Syncfusion.Blazor.Adaptors.CustomAdaptor" Key=@datamanagerkey></SfDataManager> <GridPageSettings PageSize="8"></GridPageSettings> <GridColumns> <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="@Syncfusion.Blazor.Grids.TextAlign.Center" Width="140"></GridColumn> <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn> <GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" Width="150"></GridColumn> </GridColumns> </SfGrid>
@code { public static List<Order> Orders { get; set; }
public string datamanagerkey = "1001";
public void click() { datamanagerkey = null;
} |
Regards,
Naveen
I'd like to reset it in the code for the custom adaptor
Hi Lonny,
We have reviewed your query, and it seems that you would like to reset the key
programmatically after the data has been passed to the grid. Please refer to
the code snippet and sample for more information.
Sample : https://blazorplayground.syncfusion.com/embed/LNhfCVWnUHwceulW?appbar=true&editor=true&result=true&errorlist=true&theme=bootstrap5
|
public override object Read(DataManagerRequest dm, string key) {
Console.WriteLine($"Key Now: {key}"); key = "Resetkey";
datamanagerkey = key; Console.WriteLine($"Current Key: {datamanagerkey}");
IEnumerable<Order> DataSource = Orders; if (dm.Where != null && dm.Where.Count > 0) { // Filtering DataSource = DataOperations.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator); } int count = DataSource.Cast< |
Regards,
Naveen.