具有空值的DataTables列定义

时间:2018-07-18 10:31:53

标签: jquery datatables

我的序列化JSON数组是这样的:

[
    [null, null, null, null, null],
    [null, "Rough Costing", null, null, null],
    [null, null, null, null, null],
    [null, "Client", "Ua Limited", null, null],
    [null, "Product", null, null, null],
    [null, "Pro: Name", "Idam ", null, null],
    [null, "Est.: No", null, null, null],
    [null, "Time: period  ", "43299", null, null],
    [null, "Date", "15th July - 2018", null, null],
    [null, null, null, null, null]
]

jQuery DataTables查询是这样的:

<table id="example" class="display" style="width:100%">
    <thead>
        <tr>
            <th>Column 1</th>
            <th>Column 2</th>
            <th>Column 3</th>
            <th>Column 4</th>
            <th>Column 5</th>
        </tr>
    </thead>  
</table>
$('#example').DataTable({
    "ajax": {
        "url": "/POPM_Trn_IOU/ExportToExcel",
        "dataSrc": ""
    },
});

但这仅填充第一列下的DataTables行,因为我猜没有列定义。但是同样可以正常使用here

如何在我的实际应用程序中处理此问题?

SS enter image description here

1 个答案:

答案 0 :(得分:1)

Reference Link Please check here For Full Running Example

通过这种方式您可以这样做:-

$(document).ready(function() {
    var dt = $('#example').DataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": "scripts/ids-objects.php",
        "columns": [
            {
                "class":          "details-control",
                "orderable":      false,
                "data":           null,
                "defaultContent": ""
            },
            { "data": "first_name" },
            { "data": "last_name" },
            { "data": "position" },
            { "data": "office" }
        ],
        "order": [[1, 'asc']]
    } );