データグリッド Dojo の href セル
-
26-10-2019 - |
質問
Dojo Toolkit Datagridにhrefを添えたセルをどのように置くかはわかりません。
<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でデータを取得しています。
解決
フォーマッタ関数を使用してセルを書式設定できます。たとえば、すべての書式設定関数を含む 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
グリッド内の属性。
他のヒント
Dojo Grid はセキュリティ上の理由からデフォルトで HTML タグをエスケープしますが、これを行うだけで HTML タグを有効にすることができます。
<table dojoType="dojox.grid.DataGrid" escapeHTMLInData="false" ...>
グリッドがプログラムで追加された場合はこれ
escapeHTMLInData: false
詳細はこちら:http://dojotoolkit.org/reference-guide/dojox/grid/DataGrid.html
所属していません StackOverflow