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

Adding HtmlString support

3 Answers 531 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jean-François
Top achievements
Rank 1
Jean-François asked on 29 Apr 2013, 07:42 PM
Hi, 

We have an issue using IHtmlString properties inside the grid. By default, it displays "[object Object]" in the column since, well, HtmlString is an object. However, this is ASP.NET MVC's way of saying "this string is already html-encoded".  As such, I can use @Model.Property to have a property that includes html without re-encoding it. If Property was a simple string, I would have @Html.Raw(Model.Property)

It would be nice if kendo ui's grid was to work like this as well. If we use a string, we can by-pass the html-encoding using a client template ("#= Property #"), however if we have an IHtmlString property, there is no way to display it, since it has no public properties. The only method it has is ToHtmlString(), which is what kendo's grid could use.

We temporarily bypassed this issue using a second property which calls ToHtmlString() on the original property, but native support for this type would be nicer I think.

== Overview
Work : 
columns.Bound(Function(vm) vm.PropertyAsString).ClientTemplate("#= Pharmacie.CoordonneesCompletesBruts #")

Works not : 
columns.Bound(Function(vm) vm.PropertyAsHtmlString) // Can't work, this is just an object
columns.Bound(Function(vm) vm.PropertyAsHtmlString).ClientTemplate("#= Pharmacie.CoordonneesCompletesBruts #") // Can't work, this is still just an object
columns.Bound(Function(vm) vm.PropertyAsHtmlString).ClientTemplate("#= Pharmacie.CoordonneesCompletesBruts.ToHtmlString #") // Doesn't work, this function is not replicated in JS
columns.Bound(Function(vm) vm.PropertyAsHtmlString.ToHtmlString()) // Doesn't work, not a property expression
==

Thanks,
Jni

PS : I'm posting this in the grid forum, but there are most likely other components which could benifit from this.
PS2 : I know, having properties that return HTML inside a viewmodel might not be the best idea, but, long story short, we have to for this one.

3 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 01 May 2013, 08:36 AM
Hi Jean-François,

Indeed, having properties of type HtmlString is not supported. One of the reason this is true is the fact the default JSON serializer cannot serialize this type instances by default (it is serialized as empty object). 

In order to show an HTML snippets within the Grid column cells you should bind it to the string value and set the encoded column option to false.

Regards,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jean-François
Top achievements
Rank 1
answered on 01 May 2013, 05:00 PM
Hi, 

Indeed, we used a string value for the column, but we didn't know about the encoded option. We used a client template, which achieved the save result. However, the question was more about native support for HtmlString in kendo ui. It would be nice it was treated as a string and set the encoded option to false on its own. This should be fairly easy to implement, given that the encoded option is already present. 

Thanks
0
Rosen
Telerik team
answered on 02 May 2013, 05:54 AM
Hi,

As I have already mentioned, HtmlStrings cannot be supported as they are not correctly serialized via the built-in JSON serializer. Thus, it is not possible to show them during AJAX binding as there is no data send for them.

Regards,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Jean-François
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Jean-François
Top achievements
Rank 1
Share this question
or