Data tables row.add

Data tables row.add

info@warmaster.co.zainfo@warmaster.co.za Posts: 2Questions: 1Answers: 1

Hi Guys,
Wonder if you can help me as i am struggling to add data after a new row was entered (Main data comes from AJAX, but don't want to refresh entire table. Please help:

Name Cellphone Adress Last Invoice Add Client

```getFullName and getFulladdress joins fields
table = $('#tblClient').DataTable({
"columns": [
{
"className": "details-control",
"orderable": false,
"data": null,
"defaultContent": ''
},
{ "data": getFullName },
{ "data": "Cellphone" },
{ "data": getFullAddress },
{ "data": "LastInvoice" },
{
"orderable": false,
"data": null,
"width": "15px",
"defaultContent": '<button class="btn btn-sm btn-warning btn-flat editC"><span class="fa fa-edit" style="vertical-align: middle"></span></button>'
},
{
"orderable": false,
"data": null,
"width": "15px",
"defaultContent": '<button class="btn btn-sm btn-danger btn-flat removeC"><span class="fa fa-trash-o" style="vertical-align: middle"></span></button>'
}

    ],
    "order": [[1, 'asc']]
});

and here i'm trying to link a new row...
table.row.add([ {
'Name' : 'a',
'Surname' : 'b',
'Cellphone': 'c',
'Address1' : 'd',
'Address2': 'e',
'AlternativeContact' :'f',
'City' :'g',
'Email' :'h',
'ID':'i',
'LastInvoice':'j'
}]).draw(false);
keep getting
DataTables warning: table id=tblClient - Requested unknown parameter 'Cellphone' for row 4. For more information about this error, please see http://datatables.net/tn/4

I've tried to search but not succeeding.
Should the row.add contain the entire object, or what is declared in the "columns": section?

Thanks

This question has an accepted answers - jump to answer

Answers

  • info@warmaster.co.zainfo@warmaster.co.za Posts: 2Questions: 1Answers: 1
    Answer ✓

    I've figured it out... thanks
    var data = [{
    'Name': 'a',
    'Surname': 'b',
    'Cellphone': 'c',
    'Address1': 'd',
    'Address2': 'e',
    'AlternativeContact': 'f',
    'City': 'g',
    'Email': 'h',
    'ID': 1,
    'LastInvoice': 'j'
    }];
    table.row.add(data[0]).draw(false);

This discussion has been closed.