Datatables warning - ''requested unknown parameter FirstName for row x"

Datatables warning - ''requested unknown parameter FirstName for row x"

ArunRahulArunRahul Posts: 16Questions: 4Answers: 0
edited January 2015 in Free community support

I am having datatables code as follows

 <table id="users" class="table table-striped table-bordered">
        <thead>
               <tr>
                     <th>FirstName</th>
                     <th>LastName</th>
                     <th>Name</th>
                      <th>Username</th>
                       <th>Password</th>
                       <th>Email</th>
                      <th>Role</th>
                 </tr>
         <thead>
         <tbody>

         </tbody>
</table>
```

And corresponding javascript is as follows

 userTable = $("#users").DataTable({
    serverSide: true,
    ajax: {
        url: "scripts/getusers.php",
        type: "POST",
        dataType: "json"
    },
    "columns": [
        {data: "FirstName", "orderable": true,"searchable":true,visible:false},
        {data: "LastName", "orderable": true,"searchable":true,visible:false},
        {data : null,
            "render":function(data, type, row, meta ){
            return row['FirstName']+','+row['LastName'];
        }},
        {data: "Username", "orderable": true,"searchable":true},
        {data: "Password", "orderable": true,"searchable":true,
        "render":function(data, type, row, meta ){
            return '********';
        }},
        {data: "Email", "orderable": true,"searchable":true},
        {data: "Role", "orderable": true,"searchable":true,
        "render":function(data, type, row, meta ){
            return data == 1?'Root':(data == 2?'Admin':'User');
        }}
    ],
    "language": {
        "emptyTable": "Seems no users were registered yet"
    },
    dom: 'T<"clear">lfrtip'
});

When I try to add a row as follows, though the row is added successfully it is showing the warning

userTable.row.add([data.FirstName,data.LastName,data.Username,data.Password],data.Email,data.Role).draw();

'requested unknown parameter FirstName for row 10' (my default length is 10)

To update a row I am selecting a row as shown here and then calling the following

userTable.row('.selected').data([data.FirstName,data.LastName,data.Username,data.Password],data.Email,data.Role).draw();

Same error is appearing in the above . It is saying

'requested unknown parameter FirstName for row x' (where x is the row number I am updating)

In both the cases row is added and updated successfully. But I am getting the warning.

I guess there is some problem with the render function I wrote for third column.

Also for updating (as shown above) I am calling draw method which is removing the selected class which means I cannot call the above update statement multiple times. Is there any other option. Actually the above update statement is called in a modal dialog. So a same row must be allowed to update multiple times which is not possible if draw() is called which clears the 'selected' class. Is there any solution for this?

Answers

  • ArunRahulArunRahul Posts: 16Questions: 4Answers: 0

    I got the answer. By the time control started rendering the columns it is expecting the object and I am giving an array and also while I am updating the row instead of passing the array I must pass the entire object. During addition due to a bug in my code the 'data' object has not property named FirstName. That is the reason why it is giving the warning. But table is getting updated because I am calling draw() method which reloads the entire table.

This discussion has been closed.