1

我找不到如何在 dojo 工具包数据网格中放置一个带 href 的单元格,正在使用的 od dojo 版本是 1.6 这是我的表

  <table id="billsGrid" dojoType="dojox.grid.DataGrid" data-dojo-props="escapeHTMLInData:false">
        <thead>
            <tr>
                <th field="name" width="auto">name</th>
                <th field="description" width="auto">Description</th>
                <th field="activity" width="auto">activity</th>
            </tr>
        </thead>
    </table>

我正在使用 Json 获取数据。

4

2 回答 2

3

您可以使用 formatter 函数来格式化单元格。例如,您可以声明一个包含所有格式化函数的 JavaScript 对象。

var myFormatters = {
   formatLink : function(value, index) {
        return "<a href='#'>" + value + "</a>";
   }
};

然后在网格中,

<table id="billsGrid" dojoType="dojox.grid.DataGrid" data-dojo-props="escapeHTMLInData:false" formatterScope="myFormatters"  >
    <thead>
        <tr>
            <th formatter="formatLink" field="name" width="auto">name</th>
            <th field="description" width="auto">Description</th>
            <th field="activity" width="auto">activity</th>
        </tr>
    </thead>
</table>

您不需要为格式化程序创建范围对象,那么此格式化函数应该在全局范围内,然后您可以省略formatterScope网格中的属性。

于 2011-07-26T09:40:26.390 回答
1

出于安全原因,dojo 网格默认转义 html 标签,您只需启用 html 标签即可:

<table dojoType="dojox.grid.DataGrid" escapeHTMLInData="false" ...>

或者如果您的网格是以编程方式添加的

escapeHTMLInData: false

更多信息在这里: http ://dojotoolkit.org/reference-guide/dojox/grid/DataGrid.html

于 2011-12-16T09:30:27.470 回答