More in this section

Forums / Developing with Sitefinity / How to force DataColumnElement display HTML?

How to force DataColumnElement display HTML?

5 posts, 0 answered
  1. Anton Mernov
    Anton Mernov avatar
    110 posts
    Registered:
    03 Dec 2008
    31 May 2011
    Link to this post
    Hi guys,

    In the Products sample there is a declaration of column that displays the title of a product:
    DataColumnElement titleColumn = new DataColumnElement(gridMode.ColumnsConfig)
    {
        Name = "Title",
        HeaderText = Res.Get<Labels>().Title,
        HeaderCssClass = "sfTitleCol",
        ItemCssClass = "sfTitleCol",
        ClientTemplate = @"<a sys:href='javascript:void(0);' sys:class=""{{ 'sf_binderCommand_edit sfItemTitle sf' + UIStatus.toLowerCase()}}"">
            <strong>{{Title}}</strong>
            <span class='sfStatusLocation'>{{Status}}</span></a>"
    };
    gridMode.ColumnsConfig.Add(titleColumn);

    I'd like to use a similar configuration to display description.
    DataColumnElement descriptionColumn = new DataColumnElement(gridMode.ColumnsConfig)
    {
        Name = "Description",
        HeaderText = Res.Get<ProductsResources>().Description,
        ClientTemplate = @"{{Description}}"
    };
    gridMode.ColumnsConfig.Add(descriptionColumn);

    The description have to be displayed with HTML formatting:
    This is the first description of product.

    Currently, it shows the description with HTML tags in the plain text mode:
    This is the first <b>description</b> of product.

    Is there a way to accomplish this?

    Best regards,
    Anton
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    31 May 2011
    Link to this post
    Hello Anton,

    You can try using

    • HeaderCssClass- Determines the css class of the header for this data item.
    • ItemCssClass- Determines the css class for the item.

    Here is a list with all properties of the ColumnElement that you can set
    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Victor
    Victor avatar
    94 posts
    Registered:
    15 Jun 2011
    19 Dec 2011
    Link to this post
    That's fine for style, but what if the field actually holds HTML (such as links).  Is there anyway to have that HTML not be escaped?
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    20 Dec 2011
    Link to this post
    Hi Victor,

    This is the purpose of ClientTemplate . HeaderCssClass and ItemCssClass are supposed to serve only css.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Victor
    Victor avatar
    94 posts
    Registered:
    15 Jun 2011
    20 Dec 2011
    Link to this post
    Sorry my question was unclear.  I have a field in my database called myHTML, this field can contain various links, bold, italics, etc.  and is stored in the database as HTML in a string field.

    In my client template I have the following string "<div>{{myHTML}}</div>".

    When the grid is bound on the client, the field appears as plain text, not HTML.  The HTML gets "escaped" so instead of seeing a link, I literally see the "a" tag. 

    If there a way to avoid this?


5 posts, 0 answered