Cannot add a row to a table bound to an ajax get

Cannot add a row to a table bound to an ajax get

barnsletbarnslet Posts: 2Questions: 1Answers: 0
edited July 2017 in Free community support

Hi,
I have a Datatable bound to an ajax call that successfully populates my table with data.

simpleGet(url).then( function(apiResponse)
{
    var myData = apiResponse;
    //alert(JSON.stringify(data,null,4));

    $('#example').DataTable({
    "data": myData,
    "columns": [
        { "data": "OrderDate" },
        { "data": "DcName" },
        { "data": "StoreName" },
        { "data": "StoreCode" },
        //{ "data": "" },
        { "data": "Value" }
    ],
    "scrollY": "500px",
    "scrollCollapse": true,
    "paging": false
    });

However when I then attempt to append a row to the table I get this message:

DataTables warning: table id=example - Requested unknown parameter 'OrderDate' for row 572, column 0. For more information about this error, please see http://datatables.net/tn/4

    $('#example').DataTable().row.add( [{
        "OrderDate": '2017/04/01',
        "DcName": 'Western Cape',
        "StoreName": 'x STORE',
         "StoreCode": 30000,
        "Value": 4}
    ] ).draw( false );

I have tried to interpret the error message - but to no avail. Should i be adding to the data source? Not sure how to add a row when the table is bound to a collection. Was working perfectly for static HTML table.
Thanks

Answers

  • barnsletbarnslet Posts: 2Questions: 1Answers: 0

    My sincere apologies
    the '[' in the row.add function caused the problem.
    Could someone delete this question

This discussion has been closed.