DataTable返回未知参数,但已定义

时间:2019-09-04 08:00:46

标签: jquery datatable

我有这个DataTable

<table class="table table-striped table-scrollable" id="plans-table">
    <thead class="text-primary">
        <tr>
            <th></th>
            <th><?= lang('title') ?></th>
            <th><?= lang('size') ?></th>
            <th><?= lang('rooms') ?></th>
            <th><?= lang('baths') ?></th>
            <th><?= lang('description') ?></th>
            <th><?= lang('price') ?></th>
            <th class="disabled-sorting text-right"><?= lang('actions') ?></th>
        </tr>
    </thead>
    <tbody>
    </tbody>
</table>

通过以下方式初始化:

let dataTable = $('#plans-table').DataTable({
    columns: {
        data: 'feature_image',
        render: function (data, type, row) {
            return '<div class="photo"><img src="' + data + '" /></div>';
        }
    },
    { data: 'title' },
    { data: 'size' },
    { data: 'rooms' },
    { data: 'baths' },
    { data: 'description' },
    { data: 'price' },
    {
        data: null,
        render: function (data, type, row) {
            return '<div class="d-flex justify-content-between" data-plan-id="' + data.id + '">' +
                '<a href="#" class="btn btn-link btn-primary btn-just-icon recover d-none"><i class="material-icons">restore_from_trash</i></a>' +
                '<a href="#" class="btn btn-link btn-warning btn-just-icon edit"><i class="material-icons">dvr</i></a>' +
                '<a href="#" class="btn btn-link btn-danger btn-just-icon remove"><i class="material-icons">close</i></a></div>';
        }
    }
});

我想使用此方法向表中添加新行:

let row = 
{
    'feature_image': $('.picture-preview').attr('src'),
    'title': $('#plan-title').val(),
    'size': $('#plan-size').val(),
    'rooms': $('#plan-rooms').val(),
    'baths': $('#plan-baths').val(),
    'description': $('#plan-description').val(),
    'price': $('#plan-price').val()
};

dataTable.row.add(row).draw().node();

此返回:

  

DataTables警告:表id = plans-table-请求的第0行第1列的未知参数“标题”。有关此错误的更多信息,请参见http://datatables.net/tn/4

我看到了很多与此相关的帖子,但是我无法解决。我正在将对象传递给add方法,我做错了什么?

0 个答案:

没有答案