user7038798
user7038798

Reputation:

Javascript dataTables populating data issue (no errors returned)

I am using data tables and trying to popular a table with data.

The data I have looks like this:

<table id="mytable" class="display" width="100%"></table>

{
  "users": [
    {
      "id": "6700",
      "user": {
        "firstName": "somename"
      },
      "Count": 0
    }
  ]
}

So this is what I've done:

var dataSet = {
    "users": [
        {
            "id": "6700",
            "user": {
                "firstName": "somename"
            },
            "Count": 0
        }
    ]
};

jQuery('#mytable').DataTable( {
    data: dataSet,
    columns: [
        { "users": "id" }
    ]
});

I'm am not getting any errors but the data is not inserted either.

What I'm I doing wrong here?

Upvotes: 1

Views: 20

Answers (1)

Gyrocode.com
Gyrocode.com

Reputation: 58870

In data option you need to provide variable that contains array of objects (dataSet.users). Also in columns.data option you need to define property within each object in the array (id).

Corrected code is shown below.

jQuery('#mytable').DataTable( {
    "data": dataSet.users,
    "columns": [
        { "data": "id", "title": "ID" }
    ]
});

See this example for demonstration.

Upvotes: 1

Related Questions