Added data (size undefined) does not match known number of columns (6)
Added data (size undefined) does not match known number of columns (6)
New DataTables user here. Version 1.7.5. I am running into this error while trying to build an AJAX loaded data table. When I load it directly it loads just fine, but I am trying to handle over 10k rows of data, so AJAX is the only real way to do it.
When the table loads the error is "DataTables warning (table id = 'edit-listvenues'): Added data (size undefined) does not match known number of columns (6)". I have been reading over the forums and found all kinds of suggestions about this error where the number of columns don't match, but in this case they do, and they all knew how many columns were being loaded.
So, here is my initial table definition:
[code]
ID
Name
City
Zip
Featured
Action
Loading data from server
jQuery(document).ready(function() {
DataTableBuild_venues();
});
function DataTableBuild_venues(){
if ($("#edit-listvenues tbody tr").length > 0 ) {
$("#edit-listvenues").dataTable( {
"sPaginationType": "full_numbers",
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "/index.php/admin/venue/indexajaxdata"
});
}
}
[/code]
When I send back json data, this is what is getting sent back: (It's validated from jsonlint.com)
[code]
{
"sEcho": 1,
"iTotalRecords": 7780,
"iTotalDisplayRecords": 7780,
"aaData": [
{
"VenueID": "1",
"VenueName": "Unknown Venue",
"City": "Woodstock",
"PostalCode": "60098",
"featured": "0",
"Action": "Edit<\/a>"
},
{
"VenueID": "3",
"VenueName": "328 Performance Hall",
"City": "Nashville",
"PostalCode": "37201",
"featured": "0",
"Action": "Edit<\/a>"
}
]
}
[/code]
As you can see, there are exactly 6 fields in the returned data and 6 in the original definition.
Any suggestions?
When the table loads the error is "DataTables warning (table id = 'edit-listvenues'): Added data (size undefined) does not match known number of columns (6)". I have been reading over the forums and found all kinds of suggestions about this error where the number of columns don't match, but in this case they do, and they all knew how many columns were being loaded.
So, here is my initial table definition:
[code]
ID
Name
City
Zip
Featured
Action
Loading data from server
jQuery(document).ready(function() {
DataTableBuild_venues();
});
function DataTableBuild_venues(){
if ($("#edit-listvenues tbody tr").length > 0 ) {
$("#edit-listvenues").dataTable( {
"sPaginationType": "full_numbers",
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "/index.php/admin/venue/indexajaxdata"
});
}
}
[/code]
When I send back json data, this is what is getting sent back: (It's validated from jsonlint.com)
[code]
{
"sEcho": 1,
"iTotalRecords": 7780,
"iTotalDisplayRecords": 7780,
"aaData": [
{
"VenueID": "1",
"VenueName": "Unknown Venue",
"City": "Woodstock",
"PostalCode": "60098",
"featured": "0",
"Action": "Edit<\/a>"
},
{
"VenueID": "3",
"VenueName": "328 Performance Hall",
"City": "Nashville",
"PostalCode": "37201",
"featured": "0",
"Action": "Edit<\/a>"
}
]
}
[/code]
As you can see, there are exactly 6 fields in the returned data and 6 in the original definition.
Any suggestions?
This discussion has been closed.
Replies
Have you come across a solution?
My next step is going to be stepping back through the source code and seeing if I can spot the comparison that is throwing the error and see what it THINKS I have. The "size undefined" points to it's parser of the json package it's receiving.
[code]
{
"sEcho": 1,
"iTotalRecords": 7780,
"iTotalDisplayRecords": 7780,
"aaData": [
{
"1",
"Unknown Venue",
"Woodstock",
"60098",
"0",
"Edit<\/a>"
},
...
]
}
[/code]
Allowing objects to be used is something I plan to support in future versions of DataTables - although you will need to specifically tell it which columns should read which object properties.
Allan
[link]http://datatables.net/forums/comments.php?DiscussionID=4122&page=1#Item_4[/link]
I have used following code to map json received data with columns :
[code]
dataTable = jQuery('#records').dataTable( {
"aoColumnDefs" : [
{"sTitle": "My Column 1", "sName": "member_id", "aTargets": [ 0 ] },
{"sTitle": "My Column 2", "sName": "last_name", "aTargets": [ 1 ] },
{"sTitle": "My Column 3", "sName": "first_name", "aTargets": [ 2 ] }
],
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": readUrl
});
[/code]
But iam still receiving alert about column mismatch.
Thanks in advance
Allan