Conflict with dynamic row adding to a previously initialized row

Conflict with dynamic row adding to a previously initialized row

GideonGideon Posts: 3Questions: 1Answers: 0

Hi:

My page is generated with a fully finished <table>- meaning it already has <tr> inside it's <tbody>, before I converted it as a DataTable instance. But after some time, a web-service will give new data for rows to be added. The problem is that this data comes as an Object, rather than an Array. So to accommodate, I configured my DataTable initialization, added the columns property on my DataTables, and provided the data property like this

var remittanceDataGrid = $("#remittance-data-grid").DataTable({
    columns: [
        {
            data: "id",  // Previously there is no 'data' property here.
            width: "25%" // But I need tp map it for the new row's Object data
        },
        {
            data: "borrower.fullName", // Same here
            width: "20%"
        },
        ...
        {
            data: "statusCode", // And here
            width: "15%"
        }
    ],
    ...
};`

But it will cause an error saying:

DataTable warning: table id=remittance-data-grid - Requested unknown parameter 'id' for row 0. For more information about this error, please see http://datatables.net/tn/4

Can I not map data on a DataTable with a pre-existing <tbody> data? I am currently flattening first my Object before I insert it via rows.add(). I'm thinking if I could avoid that. There are some critical data in the Object that I wish not to be removed while adding it into theDataTable but will be removed since I have to flatten it first..

Replies

  • jr42.gordonjr42.gordon Posts: 305Questions: 2Answers: 49

    Based on your columns config provided, I would expect the object you are adding to be as follows

    {
       'id': 'value',
       'statusCode': 'value',
       'borrower': {
           'fullName': 'value'
       }
    }
    

    Is it? Based on the error message I would say no.

This discussion has been closed.