Added data does not match known number of columns

Added data does not match known number of columns

stevenmcstevenmc Posts: 3Questions: 0Answers: 0
edited May 2010 in General
Hi all,
I am trying my first ever implementation of DataTables, and am getting this error, "DataTables warning: Added data does not match known number of columns".

My JSON source is:
[code]{"sEcho": 0, "iTotalRecords": 2, "iTotalDisplayRecords": 2, "aaData": [ ["Company 1"],["Company 2"]] }[/code]
(Validated on http://www.jsonlint.com/)

My HTML is:
[code]



company_name




Loading data from server



[/code]

And my JQuery code is:
[code]
$(document).ready(function() {
$('#example').dataTable({
"bPaginate": true,
"bLengthChange": false,
"bFilter": true,
"bSort": true,
"bInfo": true,
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "server_processing.php",
"sPaginationType": "full_numbers",
"sDom": '<"toolbar">frtip', //Allows the toolbar to be added beside the search bar
"aoColumns": [ //This identifies column data types to aid sorting.
null,
null,
null,
{ "sType": "numeric" },
null
],
"bAutoWidth": true });
$("div.toolbar").html('Search for any contact:');

});
[/code]

I've tried using a .txt file as my JSON source, but DataTables really didn't like this. I've tried adding JSON headers to the PHP. I've viewed the JSON output directly in the browser then validated it. I would be very pleased if someone could assist me in my first DataTables venture!

Thank you community!

Replies

  • stevenmcstevenmc Posts: 3Questions: 0Answers: 0
    Ok, I've managed to figure out where I went wrong - so I thought I would post the answer here to help anyone in the future who has the same problem. There was nothing wrong with my JSON. The problem was with the following:
    [code]
    "aoColumns": [ //This identifies column data types to aid sorting.
    null,
    null,
    null,
    { "sType": "numeric" },
    null
    ],
    [/code]

    This was left over from the previous example I had copied and pasted, and obviously refers to columns which are no longer being used! So I just removed this (be careful about the commas you leave after removing them).

    Thanks DataTables!
This discussion has been closed.