0

In my Jquery Datatable I am rendering my data like this -

<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>";
 }}

        ]
        });

} );

And my HTML is like this -

<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>

In the 4th Column I want to show two different values of "Active" or "Inactive" based on the value of Active field. At the moment I can only show 0 or 1. Is there a way to change that using datatable's configuration?

2 Answers 2

1

I got the solution by doing this -

$(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>";
                 }
            }

        ]
        });

} );

I just have to take care of this in the fnRender of datatable

Sign up to request clarification or add additional context in comments.

Comments

1

Yo can use the next sentence:

$('#example').dataTable( {
   "columnDefs": [ {
   "targets": 0,
   "data": "download_link",
     "render": function ( data, type, row, meta ) {
        return '<a href="'+data+'">Download</a>';
     }
    } ]
 } );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.