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
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.
|
|
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
your assumption is correct. i receive a null.
I will send you the code shortly
THX So much
Thanks for the update , we will wait to hear from you.
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
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.
THX so much
You're welcome! We're glad the solution works for you.
We'll be closing the thread now.