如何在kendo ui网格列中显示格式化的HTML数据

时间:2013-07-26 14:53:45

标签: kendo-ui kendo-grid

我已动态地在kendo ui网格中添加了列。

我有一个名为'Formatted'的列,其数据以下列格式显示。

<div class="class1"> <div>This is <strong>bold </strong>text.</div> <div> </div> <div>This is <em>italics</em> text.</div> <div> </div> <div>This is a <a href="http://google.com/">hyperlink</a>.</div> <div> </div> <div>Bulleted list:</div> <ul> <li>Bullet #1</li> <li>Bullet #2</li> <li>Bullet #3</li></ul></div>

我希望'格式化'列显示如下数据。

This is bold text.
 
This is italics text.
 
This is a hyperlink.
 
Bulleted list:

 Bullet #1

 Bullet #2

 Bullet #3

我该怎么做?

任何人都可以帮助我。

2 个答案:

答案 0 :(得分:2)

您应该定义column template

示例:

<script id="ob-template" type="text/x-kendo-template">
    <div class="class1"> 
        <div>This is <strong>bold </strong>text.</div>
        <div> </div>
        <div>This is <em>italics</em> text.</div>
        <div> </div>
        <div>This is a <a href="http://google.com/">hyperlink</a>.</div>
        <div> </div>
        <div>Bulleted list:</div>
        <ul>
            <li>Bullet #1</li>
            <li>Bullet #2</li>
            <li>Bullet #3</li>
        </ul>
     </div>
</script>

然后,当您定义列时使用它:

$("#grid").kendoGrid({
  dataSource: ...,
  columns: [ 
    { field: "...", title: "...", template: $("#ob-template").html()}
  ]
});

答案 1 :(得分:0)

您可以使用模板属性:template:“#= rawHtmlDataVariable#”,如下所示

<div id="grid"></div>
  <script>
    $("#grid").kendoGrid({
      columns: [ {
        field: "name",
        template: "#=rawHtmlDataVariable#"
      }],
      dataSource: [ { name: "Jane Doe" }, { name: "John Doe" } ]
});

http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#configuration-columns.template