Problems loading table using array of data stored in javascript variable

Problems loading table using array of data stored in javascript variable

BarbarosaBarbarosa Posts: 17Questions: 1Answers: 0

I am trying to follow the instruction in the manual explicitly to load a table using Arrays in the section: "Data source types". The value of my variable and my initialization looks EXACTLY like the examples shown in pictures in the manual. But when the table initialization occurs I get this message:

DataTables warning: table id=fileList - Requested unknown parameter '1' for row 0, column 1. For more information about this error, please see http://datatables.net/tn/4

The value of my var data is:

[
    [
            "file-1",
            "2019-01-29T20:33:57.000163Z",
            "348"
    ],
    [
            "file-2",
            "2019-01-29T20:33:57.000167Z",
            "401"
    ],
    [
            "file-3",
            "2019-01-29T20:33:57.000171Z",
            "1314"
    ]
]

My table initialization is:

    var table = $('#fileList').DataTable({
        data: data
    });

The body section of my HTML file is:

        <body>
            <table id="fileList" class="display" style="width:100%">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Date</th>
                        <th>Size</th>
                    </tr>
                </thead>
            </table>
        </body>

It frustrating to not be able to exactly replicate the examples and they don't work. Arrays data appears to be the most simplistic yet I cannot seem to get it to load. Can anyone offer some advice?

Replies

  • BarbarosaBarbarosa Posts: 17Questions: 1Answers: 0

    Disregard. I got this working. My var was being set to a string representation of the array. I transformed it with a call to JSON.parse to turn it into a proper array and it is now working.

This discussion has been closed.