DataTables requested unknown parameter nested object

126
March 04, 2018, at 10:58 AM

Table creation;

var table = $("#tbl-inventory-report").DataTable({
    ajax: {
        url: "/api/inventory",
        dataSrc: "",
    },
    "oLanguage": {
        "sProcessing": ""
    },
    processing: true,
    columns: [
        {
            data: "Id",
            className: "visible-lg",
        },
        {
            data: "Employee.LogonName"
        }
     ]
});

Example Json Result of Ajax Request;

{  
   Id:3434,
   Employee:{  
      Id:10,
      LogonName:"Example10"
   }
}

JS Code that I get the error;

table.row.add({
     "Id": 11,     
     "Employee.LogonName": "Example11",         
}

Data loads successfully when page loaded. However, when I want to add rows later on, I get the following error. Any Idea?

Requested unknown parameter 'Employee.LogonName' for row 2856, column 1.

Answer 1

Due to the record structure defined in your inventory api, you need to change this line:

table.row.add({
    "Id": 11,     
    "Employee.LogonName": "Example11",         
}

to:

table.row.add({
    "Id": 11,
    "Employee": {
        "LogonName": "Example11"
    }
});
READ ALSO
two circles should follow the cursor – one small and one big (with delay)

two circles should follow the cursor – one small and one big (with delay)

I have seen this tendency on some websites now, where the default cursor is replaced with a new cursor – in many cases circles

119
How to store data-* attributes in <head>

How to store data-* attributes in <head>

I have some javascript that I load in my headAnd I want to reference some data attributes

81
Select current item when tabbing off Select2 input

Select current item when tabbing off Select2 input

This has been the subject of the following similar SO Question and several github issues including:

164
Fixed-Position Overlay Element Causing scrollTop() Jumping in Safari?

Fixed-Position Overlay Element Causing scrollTop() Jumping in Safari?

I have a function that applies scrollTop() to the addClass() and removeClass() attributes; however, when removeClass() is prompted, the scrollTop() causes an split-second jump to the top (top: 0) of the page, then readjusts to the current window positionIs...

113