Get await value on databaound

Hi,

I have a question which I have been trying to figure out for a good while now.
I have a grid, with rows of records. On one column I want to check if this record exists in another table by calling an async method.
The value is simply tur or false - but I cannot get this value no mattger what I try, I have tried QueryCellInfo, DataBoundHandler, Template colums - but I cannot figure it out, I know I can get the value using CustomizeCell but how do I pass the value back (true or false) to the column so data is displayed differently?

appreciate your help

3 Replies 1 reply marked as answer

VN Vignesh Natarajan Syncfusion Team July 14, 2020 04:10 AM UTC

Hi John,  
 
Greetings from Syncfusion support.  
 
Query: “On one column I want to check if this record exists in another table by calling an async method. 
 
From your query we understand that you want to call a async method during runtime (from razor code) and validate the row data based on another table value. But Blazor does not support calling asynchronous method from razor code. Please find some general links from below 
 
 
So we suggest you to store the second table datasource in a global variable in OnInitializedAsync method and perform the validation using a synchronous method using ColumnTemplate feature of Grid. Refer the below code example.  
 
<SfGrid DataSource="@OrderData" AllowPaging="true"> 
    <GridColumns> 
        <GridColumn Field=@nameof(Orders.CustomerID) HeaderText="Customer Name" Width="150"> 
            <Template> 
                @{ 
                    var val = (context as Orders); 
                    var returned = @GetValue(val); 
                    <span>@returned.ToString()</span> 
                } 
            </Template> 
        </GridColumn> 
    </GridColumns> 
</SfGrid> 
  
@code{ 
    public List<Orders> OrderData { getset; } 
    public List<Employee> EmployeeData { getset; } 
    public bool GetValue(Orders Value) 
    { 
        if (EmployeeData.Where(x => x.EmployeeName == Value.CustomerID).Count() > 0) // check the condition and return the value 
        { 
            return true; 
        } 
        else 
        { 
            return false; 
        } 
    } 
    protected override async Task OnInitializedAsync() 
    { 
        OrderData = await ForecastService.GetOrderAsync(); 
        EmployeeData = await ForecastService.GetNewData(); // store the second table datasource is global variable  
    } 
 
   
For your convenience we have prepared a sample which can be downloaded from below  
 
 
Refer our UG documentation for your reference 
 
 
Kindly get back to us if you have further queries.  
 
Regards, 
Vignesh Natarajan 


Marked as answer

JO John July 15, 2020 10:00 AM UTC

Thanks Vignesh, it's a whole new way of thinking isn't it?

I  was three days working on this and you guys come up with something in 10 minutes - I have much to learn!
Have to say I tired it and wit worked like a charm!

Thank you!


VN Vignesh Natarajan Syncfusion Team July 16, 2020 05:05 AM UTC

Hi John, 

Thanks for the update.  

We are glad to hear that you have resolved your query using our solution.  

Kindly get back to us if you have further queries.  

Regards, 
Vignesh Natarajan  


Loader.
Up arrow icon