在我的Jquery Datatable中,我正在渲染我的数据 -
<script language="javascript">
$(document).ready(function() {
$('#displayData').dataTable( {
"sAjaxSource": '../controller/securityManager.cfc?method=listAllAdmins',
"aoColumns": [
{ "mData": "ADMINNAME"},
{ "mData": "EMAIL" },
{ "mData": "LOGIN" },
{ "mData": "ACTIVE" },
{ "mData": "DATELASTLOGIN" ,
"fnRender": function (oObj) {
//alert(JSON.stringify(oObj));
return "<a href='editState?id=" + oObj.aData[0] + "'>Edit</a>";
}}
]
});
} );
我的HTML就像这样 -
<table cellpadding="0" cellspacing="0" border="0" class="display" id="displayData">
<thead>
<tr>
<th align="left" style="font-size:12px">Name</th>
<th align="left" style="font-size:12px">Email</th>
<th align="left" style="font-size:12px">Login Name</th>
<th align="left" style="font-size:12px">State</th>
<th align="left" style="font-size:12px">Last Access Date</th>
</tr>
</thead>
<tbody>
<tr>
</tr>
</tbody>
</table>
在第4列中,我想根据活动字段的值显示两个不同的“活动”或“非活动”值。目前我只能显示0或1.有没有办法使用datatable的配置来改变它?
答案 0 :(得分:1)
我通过这样做得到了解决方案 -
$(document).ready(function() {
$('#displayData').dataTable( {
"sAjaxSource": '../controller/securityManager.cfc?method=listAllAdmins',
"aoColumns": [
{ "mData": "ADMINNAME"},
{ "mData": "EMAIL" },
{ "mData": "LOGIN" },
{ "mData": "ACTIVE" ,
"fnRender": function (oObj) {
if(oObj.aData.ACTIVE == 0)
return "<a href='editState?id=" + oObj.aData.ADMINID + "'>Active</a>";
else
return "<a href='editState?id=" + oObj.aData.ADMINID + "'>In-Active</a>";
}
},
{ "mData": "DATELASTLOGIN" ,
"fnRender": function (oObj) {
//alert(JSON.stringify(oObj.aData));
//alert(oObj.aData.ADMINID)
return "<a href='editState?id=" + oObj.aData.ADMINID + "'>Edit</a>";
}
}
]
});
} );
我只需要在数据表的fnRender
中处理这个问题答案 1 :(得分:0)
您可以使用下一个句子:
$('#example').dataTable( {
"columnDefs": [ {
"targets": 0,
"data": "download_link",
"render": function ( data, type, row, meta ) {
return '<a href="'+data+'">Download</a>';
}
} ]
} );