Render cell as a color

Hi, 


I need to render a cell in a Grid as a color, as shown in attached file (column 'Cor'), replacing the hex values with it's corresponding color.

Thanks in advance.

Regards,
Fausto



Attachment: Doctors_b4f83e48.rar

3 Replies 1 reply marked as answer

JP Jeevakanth Palaniappan Syncfusion Team November 9, 2020 12:55 PM UTC

Hi Fausto, 

Greetings from Syncfusion support. 

We have validated your query and found that you need to apply color to cells based on the data’s in the grid. We suggest you to achieve your requirement by using the QueryCellInfo event of the grid and refer the corresponding color in the styles. Please refer the below documentation for your reference. 


Other Documentation regarding customization of grid styles 

Please get back to us if you have any other queries. 

Regards, 
Jeevakanth SP. 



FA Fausto November 10, 2020 01:37 PM UTC

Hi, 


In the documentation, css is applied to a certain condition; in my case, the color comes directly from a database table:

                            <GridColumn Field = @ nameof (InfoMedicos.DoctorColor) HeaderText = "Cor"
                                        Width = "220"> </GridColumn>

What I want to do is show the color in the column, replacing it's value with a corresponding color. 

Makes sense?

Regards, 
Fausto


JP Jeevakanth Palaniappan Syncfusion Team November 11, 2020 11:15 AM UTC

Hi Fausto, 

We suggest you to achieve your scenario by using the column template feature of the grid. Please find the below code snippet and the sample for your reference. 

        <GridColumn HeaderText="Employee Image" TextAlign="TextAlign.Center" Width="120"> 
            <Template> 
                @{ 
                    var employee = (context as EmployeeData); 
                    <div style="color:@employee.Color"> 
                        @employee.Color 
                    </div> 
                } 
            </Template> 
        </GridColumn> 



Please get back to us if you need further assistance. 

Regards, 
Jeevakanth SP. 


Marked as answer
Loader.
Up arrow icon