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

Binding and displaying information from complex C# objects

1 Answer 377 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dave
Top achievements
Rank 1
Dave asked on 11 Aug 2015, 02:51 PM

Hello,

 If the Telerik controls do not support this, then I would like to know. Thanks in advance

 I have a Grid that binds to a ViewModel, that in turn has 2 other types of classes as its properties. I am trying to populate the grid rows with both, and either property could be Null. In one of these classes, there is a property that is a List<Skill> where each of the Skills are classes that has a string that I need to concatenate into a larger one to display for the 'Skill' grid column. Right now I'm just making the concatenated string in the controller and adding an extra property onto my ViewModal:

 columns.Bound(p => p.SkillsDisplayed).Title("Skill").ClientTemplate("<p>#= SkillsDisplayed ? SkillsDisplayed : '' #</p>");

 My question is: is there a way to put a Razor block in the ClientTemplate (or some other way in the column binding) to iterate through the List<Skill> and concatenate those object's strings together and display the resulting string? I have already tried this with javascript similar to the above, but the nested '#'s' makes such a function highly unreadable and I'm not sure I can achieve that anyways. Is this even possible?

1 Answer, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 13 Aug 2015, 08:15 AM

Hello Dave,

 

The ClientTemplate must be a string which might contains client template. It will be evaluated on client when the widget is binding. The template might contain valid JavaScript. 

 

That said you should be able to implement the client template in the same manner to concatenate the elements of array with JavaScript in similar manner as on server (using Razor).

 

Example of such client template (assuming myField is either null or collection of strings):

 

.ClientTemplate("#= myField == null ? 'N/A' : myField.join(', ') #")

 

 

In browser console you can test the output of the above template as shown bellow:

 

  - kendo.template("#= myField == null ? 'N/A' : myField.join(', ') #")({myField: null})

- kendo.template("#= myField == null ? 'N/A' : myField.join(', ') #")({myField: ["foo", "bar", "baz"]})

 

Regards,
Nikolay Rusev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Dave
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Share this question
or