Skip to content Skip to sidebar Skip to footer

Datatables Multiple Tables From Multiple Json Arrays

I want to output two tables, each sourcing information from two separate arrays within the same JSON source, but for some reason my code doesn't work. JSON Message: { 'Policies'

Solution 1:

You are not iterating through your JSON variable. As prabodhprakash suggested, writing "Policies" and "Services" won't help either.

I suggest you to take a look at this fiddle

You can initialize multiple datatables with the same syntax that you use for initializing a single one:

var json = {
  "Policies": [{
    "name": "A",
    "id": "1",
    "score": "0"
  }],
  "Services": [{
    "name": "B",
    "id": "2",
    "score": "0"
  }]
}


var policyTable = $("#policies-table").DataTable({
  "data" : (json.Policies),
  "columns": [
        { "data": "name" },
        { "data": "id" },
        { "data": "score" }]
});

var serviceTable = $("#services-table").DataTable({
    "data" :(json.Services),
    "columns": [
        { "data": "name" },
        { "data": "id" },
        { "data": "score" }]
});

Post a Comment for "Datatables Multiple Tables From Multiple Json Arrays"