fnAddData fails with 'TypeError: a is null'

fnAddData fails with 'TypeError: a is null'

ufkufk Posts: 6Questions: 1Answers: 0
edited August 2013 in General
Hello.
I'm using DataTables 1.9.4 with jQuery 2.0.3

I'm trying to add a row to the table using

oTable.fnAddData(['aa','bb','cc','dd']);

but when I add a row I get an error from firebug
'TypeError: a is null'

I tried entering an object with data... array.. anything that I try to add produces this error.

how can I properly had data to the table ?

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Please see: http://datatables.net/forums/discussion/12899/post-test-cases-when-asking-for-help-please-read
  • ufkufk Posts: 6Questions: 1Answers: 0
    test case at http://www.myalcoholist.com:8082/cocktail-management/cocktail/add-cocktail

    here you can see that on initialize of the page i have the following:
    [code]
    oTable=$('#drinksTable').dataTable({
    'bJQueryUI': true,
    "sPaginationType": "full_numbers",
    });
    [/code]
    and below that I have
    [code]
    oTable.fnAddData(['aa','b','c','d']);
    [/code]

    I tried the same with adding an object:
    [code]
    var tableJsonString = '[{"drink_flavor_type_name":"dfdsdfs","drink_brand_name":"sdfsdsfsdf","global_image_id":null,"drink_ingredients":"fds","is_transparent":"0","liquid_color_type_name":"dfsdfsdfd","alcohol_by_volume":"3343"},{"drink_flavor_type_name":"dfs","drink_brand_name":"sdf","global_image_id":null,"drink_ingredients":"dfsf","is_transparent":"0","liquid_color_type_name":"dfsdf","alcohol_by_volume":"34"},{"drink_flavor_type_name":"fdfs","drink_brand_name":"sdfsf","global_image_id":null,"drink_ingredients":"sdfs","is_transparent":"0","liquid_color_type_name":"sdsf","alcohol_by_volume":"32"},{"drink_flavor_type_name":"sdfs","drink_brand_name":"sdfsdf","global_image_id":null,"drink_ingredients":"dfds","is_transparent":"0","liquid_color_type_name":"dsdf","alcohol_by_volume":"34"},{"drink_flavor_type_name":"sdfds","drink_brand_name":"sdefs","global_image_id":null,"drink_ingredients":"dsfdf","is_transparent":"0","liquid_color_type_name":"fdsfs","alcohol_by_volume":"34"}]';
    var tableObj = JSON.parse(tableJsonString);
    oTable.fnAddData(tableObj);
    [/code]

    but i got the exact same results.

    what am i missing ?
  • ufkufk Posts: 6Questions: 1Answers: 0
    I resolved the issue. i needed to create the basic structure of the table first.
    means to add a thead line with tr and th to specify how many columns i have. I thought that this is done automatically when entering first line with ob ject (columnname=>columnvalue), but instead i'm adding data as arrays to the already defined columns.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    I don't see a DataTables on the page, just an HTML table snippet, so I'm not sure what is going wrong, but yes, if you define the number of columns width aoColumns, then DataTables should cope just fine. You obviously need to use the same data structure for the table (objects or arrays) all the way thorugh.

    Allan
This discussion has been closed.