开发者

DataTable How to add Column render from JSON

HTML:

<table cellpadding="0" cellspacing="1" border="0" class="display" id="TableId">
    <thead>
        <tr>
            <th>Name</th>
            <th>Entry</th>
            <th>Exit</th>
        </tr>
    </thead>
    <tbody>
    </tbody>
</table>

dataTable function:

$('#TableId').dataTable({
        "bProcessing": true,
        "bInfo": false,
        "sAjaxSource": '/JSON/Path',
        "bAutoWidth": fal开发者_开发问答se,
        "bRetrieve":true
    });

JSON:

{"aaData":[ ["Name 1","9516","4851"],
            ["Name 2","251304","127283"]
            ]}

I'm trying to add Column calc different between Entry and Exit.

How can it be done?


you can use fnRowCallback option to get that . add calc column in markup

    "fnRowCallback": function( nRow, aData, iDisplayIndex ) {
        /* Append the grade to the default row class name */
        var diff = aData[1]-aData[2];
        $('td:eq(3)', nRow).html(diff);
        return nRow;
    },
    "aoColumnDefs": [ {
            "sClass": "center",
            "aTargets": [ -1, -2 ]
    } ]

refer :fnRowCallback example here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜