0

I am attempting to set the source of my DataTable as an array, but I am getting this error:

Uncaught Error: DataTables warning: table id=my-table - Requested unknown parameter '0' for row 0, column 0

This is my syntax that I am wanting to use:

<script type="text/javascript">
var information = <?php echo json_encode($data) ?>;
alert(information.toString());
    $(document).ready(function () {
        $('#my-table').dataTable({
            data: information,
            columns: [
                { title: 'Employee' },
                { title: 'TotalSales' },
                { title: '30DaySales' },
                { title: '60DaySales' }
            ]
        });
    });
</script>

What alterations need to be made to the code so that the error is removed and the DataTable is displayed?

EDIT
And below is the output of console.log so you can see the format my array is in.

Console.log(JSON.stringify(information[0]))
[{"Employee":"Mitch McConell","Total Sales:"1,000.00","30DaySales:"750.00","60DaySales":"350.00"}]
1

1 Answer 1

1

I don't really know Data Table well, but it looks like you're mixing up the title and data properties.

I think you need to include the data property on your columns.

            columns: [
                { data: 'Employee' },
                { data: 'TotalSales' },
                { data: '30DaySales' },
                { data: '60DaySales' }
            ]
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.