Change the color of a table cell depending on the value contained in a secondary table

Hi there, in a grid 

I would like to change the color of a cell depending with the value contained in a secondary lookup table of the first one. 

Im my service i have this 

var leadactivities = await _context.LeadActivities

   .Include(c => c.LeadActivityType)

   .Include(c => c.LeadActivityStatus)

   .Include(c => c.LeadActivityFeedBack)

   .ToListAsync();

return leadactivities;

the query is correct 



in the grid this code shows me the right color I chose for the type of activity

 <GridColumn Field="LeadActivityType.Color" HeaderText="Color" TextAlign="Syncfusion.Blazor.Grids.TextAlign.Left" Width="60"></GridColumn>




but this code don't works  "LeadActivityType" is NULL

public void CellInfoHandler(QueryCellInfoEventArgs<LeadActivity> Args)

{

    Args.Cell.AddClass(new string[] { Args.Data.LeadActivityType.Color });

 }


may I must do something with GridColumn Template ? 


THX so much 


7 Replies

PS Prathap Senthil Syncfusion Team August 6, 2024 01:37 PM UTC

Hi Francesco Pruneri,

Based on your query, we suspect that you have retrieved the data from an API and assigned the list of data using the grid's DataSource property. However, while the complex column values are displayed in the grid, you are receiving null values when using the queryCellInfo event data. We were unable to reproduce the reported issue when attempting to replicate it. For your reference, we have attached a screenshot and sample. So, to
further proceed with the reporting problem, we require some additional clarification from your end. Please share the below details to proceed further at our end.


  1. Share with us a grid code snippet with the model class.
  2. Kindly share with us your attempts to reproduce the reported issue on the attached sample.


Sample: https://blazorplayground.syncfusion.com/embed/VNhfDvXRgATCSWws?appbar=true&editor=true&result=true&errorlist=true&theme=bootstrap5

Above-requested details will be very helpful in validating the reported query at our end and providing a solution as early as possible. Thanks for your understanding.


Regards,
Prathap Senthil




FP Francesco Pruneri August 6, 2024 01:46 PM UTC

your assumption is correct. i receive a null.

I will send you the code shortly

THX So much



PS Prathap Senthil Syncfusion Team August 7, 2024 11:17 AM UTC

Thanks for the update , we will wait to hear from you.



FP Francesco Pruneri August 9, 2024 10:34 AM UTC

i changed my strategy. i use the tamplate

and i did a mistake i have 2 record with 

@tipoattivita.LeadActivityTypeId = null 



then i wrote 


var tipoattivita = (context as LeadActivity);

@if (@tipoattivita.LeadActivityTypeId != null)

{

<div style="background-color:@tipoattivita.LeadActivityType.Color">

<span>@tipoattivita.LeadActivityType.Name</span>

</div>

}


this is ok 


now i'll try to do the fix for original codee 



PS Prathap Senthil Syncfusion Team August 12, 2024 10:52 AM UTC


Yes ,Your approach with the template looks good for handling null values. To fix the original code, ensure you check for null values before accessing properties to avoid runtime errors.



FP Francesco Pruneri August 12, 2024 05:44 PM UTC

THX so much



PS Prathap Senthil Syncfusion Team August 13, 2024 02:04 PM UTC

You're welcome! We're glad the solution works for you. We'll be closing the thread now.


Loader.
Up arrow icon