This is a migrated thread and some comments may be shown as answers.

Cell Style in Json Data

3 Answers 228 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matteo Fabris
Top achievements
Rank 2
Matteo Fabris asked on 19 Feb 2021, 08:25 AM

Hello.

I'm developing with Kendo Grid and I have a question about styling cell of every row.

I've already read some articles to style every cell in databound event.

Can I add styling rule in JSON Data Passed to Kendo Grid?

In my case I have a datatable(vb.net) that I convert to json before pass to kengo grid.

My datatable has 3 column and 50 rows.

1° col: Name / 2° col: Surname / 3° col: Style.

Every row can have a different "Style" content.  "Style" is the style that I need to apply to 1° and 2° column.

Example:

PAUL   BEAN    color:red;    

STEVE    JOBS    text-align:center;

SAM    SMITH    background-color: green;

{"data":[{"Name": "Paul", "Surname":"Bean","Style":"color:red"}, {"Name": "Steve", "Surname":"Jobs","Style":"text-align:center"}, {"Name": "Sam", "Surname":"Smith","Style":"background-color: green;"}]}

 

Can you explain If is possibile styling on json "data"?

I've already use databound event and I Iterate every rows but it is very slow.

Are there any alternatives?

 

thanks!

 

3 Answers, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 22 Feb 2021, 02:43 PM

Hi Matteo,

One way to achieve that is to define a custom rowTemplate as shown in the following demo:

Please note that within the row template you have access to all fields of the model.

Regards,
Georgi
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Matteo Fabris
Top achievements
Rank 2
answered on 01 Mar 2021, 08:50 AM

Hello Georgi,

thanky you for reply.

Can you explain me how to define row template at runtime?

Thanks

0
Georgi
Telerik team
answered on 02 Mar 2021, 11:19 AM

Hi Matteo,

I've created a small sample which demonstrates how to iterate through the fields of the model and create a row template dynamically:

I hope this helps.

Regards,
Georgi
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Grid
Asked by
Matteo Fabris
Top achievements
Rank 2
Answers by
Georgi
Telerik team
Matteo Fabris
Top achievements
Rank 2
Share this question
or