Adding HtmlString support

4 posts, 0 answers
  1. Jean-François
    Jean-François avatar
    26 posts
    Member since:
    Dec 2012

    Posted 29 Apr 2013 Link to this post

    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.
  2. Rosen
    Admin
    Rosen avatar
    3253 posts

    Posted 01 May 2013 Link to this post

    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!
  3. Jean-François
    Jean-François avatar
    26 posts
    Member since:
    Dec 2012

    Posted 01 May 2013 Link to this post

    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
  4. Rosen
    Admin
    Rosen avatar
    3253 posts

    Posted 02 May 2013 Link to this post

    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!
Back to Top