简体   繁体   English

DataTable如何从JSON添加列渲染

[英]DataTable How to add Column render from JSON

HTML: 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: dataTable函数:

$('#TableId').dataTable({
        "bProcessing": true,
        "bInfo": false,
        "sAjaxSource": '/JSON/Path',
        "bAutoWidth": false,
        "bRetrieve":true
    });

JSON: 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 . 您可以使用fnRowCallback选项获取该信息。 add calc column in markup 在标记中添加calc列

    "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 在这里参考: fnRowCallback示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM