Daniel Casserly
Daniel Casserly

Reputation: 3543

Warning: Requested unknown parameter '0' for row 0

I have the following code:

var dummyData = {
    "activities": [
        { "date": "19/06/2015 19:00", "user": "Dan", "display": "First Item" },
        { "date": "19/06/2015 19:00", "user": "Andrew", "display": "Second Item" },
        { "date": "19/06/2015 19:00", "user": "Trevor", "display": "Third Item" },
        { "date": "19/06/2015 19:00", "user": "Bob", "display": "Fourth Item" }
    ]
};

$("#sysActTable").dataTable({
    "data": dummyData.activities,       
});

I have tried several variations but I am always getting the error that points to this page. My HTML is as follows:

<table id="sysActTable" class="table table-hover" style="margin-bottom:0px">
                        <thead>
                            <tr>
                                <th style="width:20%">Date</th>
                                <th style="width:30%">User</th>
                                <th style="width:50%">Display</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td style="width:20%"></td>
                                <td style="width:30%"></td>
                                <td style="width:50%"></td>
                            </tr>
                        </tbody>

again I have tried a number of varieties. Why am I getting this error below?

DataTables warning: table id=sysActTable - Requested unknown parameter '0' for row 0

Upvotes: 1

Views: 1396

Answers (1)

Gyrocode.com
Gyrocode.com

Reputation: 58870

The problem is that your data is an array of objects. By default, DataTables expects data to be an array of arrays.

You need to use columns.data option to describe your data structure.

$("#sysActTable").dataTable({
    "data": dummyData.activities,
    "columns": [
       { "data": "date" },
       { "data": "user" },
       { "data": "display" }
    ]
});

Upvotes: 3

Related Questions