Added data (size undefined) does not match known number of columns (6)

Added data (size undefined) does not match known number of columns (6)

cchubbcchubb Posts: 4Questions: 0Answers: 0
edited February 2011 in General
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?

Replies

  • cchubbcchubb Posts: 4Questions: 0Answers: 0
    Forgot to mention: Once it throws the warning and fails to load the table, the console also logs an error "aDataSupplied.slice is not a function" identified in jquery.dataTables.js line 2597. But I figured that was because it didn't actually load the data.
  • grrlsendlightgrrlsendlight Posts: 19Questions: 0Answers: 0
    Looks like we're having the same problem: http://datatables.net/forums/comments.php?DiscussionID=4118

    Have you come across a solution?
  • cchubbcchubb Posts: 4Questions: 0Answers: 0
    No, no solution yet. I just posted it on Friday, but I am completely stumped. I have been over it every which way to see if I am missing something or have an extra comma or something, but it's not obvious, whatever the problem is.

    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.
  • grrlsendlightgrrlsendlight Posts: 19Questions: 0Answers: 0
    Me too! My developer actually just generated the JSON as an array, which we hope DataTables will take instead of worrying about parsing. Fingers crossed.
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    You are sending back aaData as an array of objects, rather than an array of arrays. At the moment DataTables has no way of knowing what property in your object applies to which column, and therefore can't render it! The expected return is like this:

    [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
  • bluesapphirebluesapphire Posts: 17Questions: 0Answers: 0
    Iam also facing same problem. When applied in your provided solution in the following link :
    [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
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    There is no capability in DataTables to use objects in the JSON returned from the table at this time. sName will not map object properties to the table columns (although this is what I propose for the next major version of DataTables) - a 2D array called aaData must be given.

    Allan
  • cchubbcchubb Posts: 4Questions: 0Answers: 0
    Allan, thank a 2^10! That was just the problem. I don't know why I didn't see that before. If I get a few minutes to figure out how to fix it so that it can take associative JSON instead of simple arrays, Ill send you the patch files.
This discussion has been closed.