无法获取 DataTable 以加载所有数据

Cannot get DataTable to load all data

数据似乎有问题,因为我在执行以下命令时得到 Requested unknown parameter 2 for row 0

var items = $('#items').DataTable({
        dom: "<'row'<'col-md-6'l><'col-md-6'f>r>t<'row'<'col-md-6'i><'col-md-6'p>>",
        paginationType: "full_numbers",
        language: {
            lengthMenu: "_MENU_ items per page"
        },
        processing: true,
        serverSide: true,
        stateSave: true,
        ajax: {
            url: "items/data",
            method: 'post'
        },
        columnDefs: [
            {
                targets: ['th-image'],
                searchable: false,
                data: 'image_url',
                render: function (data, type, full) {
                    return '<img src="' + data + '" alt="thumbnail" class="img-thumbnail" />';
                }
            },
            {
                targets: ['th-manufacturer'],
                data: 'manufacturer',
                render: function (data, type, full) {
                    var manufacturer = data.substring(0, 40);

                    if (data.length > 40)
                        manufacturer += '...';

                    return manufacturer;
                }
            },
            {
                targets: ['th-title'],
                data: 'title',
                render: function (data, type, full) {
                    var title = data.substring(0, 40);

                    if (data.length > 40)
                        title += '...';

                    return title;
                }
            },
            {
                targets: ['th-actions'],
                data: 'actions',
                searchable: false,
                sortable: false
            },
            {
                targets: ['th-id'],
                data: 'id',
                searchable: true,
                visible: false
            }
        ]
    });

关于这个table:

<table class="table table-striped table-bordered" id="items">
<thead>
    <tr>
        <th class="th-image">Image</th>
        <th class="th-manufacturer">Manufacturer</th>
        <th class="th-mpn">MPN</th>
        <th class="th-upc">UPC</th>
        <th class="th-title">Title</th>
        <th class="th-actions">Actions</th>
    </tr>
    </thead>
    <tbody></tbody>
</table>

字段 imagemanufacturertitleactions 都正确显示,但是 mpnupc 是空的在服务器数据响应中有值。

我在使用相同类型的初始化值之前创建了这样的数据表,而不需要 columns 值,所以我可能遗漏了一些明显的东西,但我还没有找到它。

DataTables 1.10.7.

因为您要返回对象数组,所以您需要使用 columnscolumnDefs 选项定义所有列数据。来自 manual:

The down side of using objects is that you need to explicitly tell DataTables which property it should use from the object for each column. This is done using the columns.data and / or columns.render options.

如下所示将 mpnupc 数据属性的定义添加到 columnDefs 以解决问题。

        {
            targets: ['th-mpn'],
            data: 'mpn'
        },
        {
            targets: ['th-upc'],
            data: 'upc'
        },