0

在我的 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 列中,我想根据 Active 字段的值显示两个不同的“Active”或“Inactive”值。目前我只能显示 0 或 1。有没有办法使用数据表的配置来改变它?

4

2 回答 2

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 中处理这个

于 2013-02-11T13:07:43.500 回答
1

哟可以用下一句:

$('#example').dataTable( {
   "columnDefs": [ {
   "targets": 0,
   "data": "download_link",
     "render": function ( data, type, row, meta ) {
        return '<a href="'+data+'">Download</a>';
     }
    } ]
 } );
于 2020-11-12T17:27:25.467 回答