Null errors on Simple Implementation

Null errors on Simple Implementation

pbrstreetgangpbrstreetgang Posts: 6Questions: 0Answers: 0
edited September 2010 in General
I have what I believe to be a very simple implementation of DataTables 1.7.2. I am running my own AJAX script that goes out and retrieves data based on a user's actions. The returned data set is put into an array of JavaScript objects and these are subsequently passed to a function where each object is displayed as a row using DataTables. And this all works fine.
However when a user reruns the AJAX call, i want to reset the table using oTable.fnDestroy() and then repopulate it with the data returned from the AJAX call. However, when I try this using jquery.dataTables.min.js I get a 'a is null' error:
Line 45:
[code]
a.oClasses.sSortableNone;b.sSortingClassJUI=""}else if(j.inArray("asc",b.asSorting)!=-1&&j.inArray("desc",b.asSorting)==-1){b.sSortingClass=a.oClasses.sSortableAsc;b.sSortingClassJUI=a.oClasses.sSortJUIAscAllowed}else if(j.inArray("asc",b.asSorting)==-1&&j.inArray("desc",b.asSorting)!=-1){b.sSortingClass=a.oClasses.sSortableDesc;b.sSortingClassJUI=a.oClasses.sSortJUIDescAllowed}}function w(a,b){if(b.length!=a.aoColumns.length&&a.iDrawError!=a.iDraw){J(a,0,"Added data (size "+b.length+") does not match known number of columns ("+
[/code]

When i try just using jquery.dataTables.min.js, i get the error 'oSettings is null'

Line 2477:
[code]
if ( aDataSupplied.length != oSettings.aoColumns.length &&
[/code]

I tried declaring oSettings in my implementation, but this has done nothing to resolve the issue.
Any help anyone can provide is appreciated.
Thanks,

pbr

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    If you run DataTables without the min version (i.e. the unpacked version), where does the error say it is, and what is the are at that point. Can you show us you initialisation code and ideally link to an example?

    Thanks,
    Allan
  • pbrstreetgangpbrstreetgang Posts: 6Questions: 0Answers: 0
    thanks for your response. When I used the unpacked version, i get the error:

    oSettings is null

    In a tag in the head, I initialize the table with:
    [code]
    var oTable;

    $(document).ready(function()
    {
    oTable = $('#resultSet').dataTable();
    });
    [/code]

    the table is defined in the body as:

    [code]



    Col 1
    Col 2
    Col 3
    Col 4
    Col 5





    [/code]

    i use a for loop in the following function to populate the table once the AJAX call returns:

    [code]
    function PopulateResultSet(resultSet)
    {
    for(i = 0; i < resultSet.length; i++)
    {
    oTable.fnAddData([
    resultSet[i].val1,
    resultSet[i].val2,
    resultSet[i].val3,
    resultSet[i].val4,
    resultSet[i].val5
    ]);
    }
    }
    [/code]

    when the AJAX call is rerun, I run the following command, which appears to be triggering the JS error:

    [code]
    oTable.fnDestroy();
    [/code]

    This page is still in development and therefore is entirely local, so I cannot point you to an example online.
    Thanks for any debugging help you can provide.

    pbr
  • pbrstreetgangpbrstreetgang Posts: 6Questions: 0Answers: 0
    one addendum-

    Mozilla identifies the JS error in the jquery.DataTables.js file in the function at line 2477:

    [code]
    function _fnAddData ( oSettings, aDataSupplied )
    {
    /* Sanity check the length of the new array */
    if ( aDataSupplied.length != oSettings.aoColumns.length &&
    oSettings.iDrawError != oSettings.iDraw )
    {
    _fnLog( oSettings, 0, "Added data (size "+aDataSupplied.length+") does not match known "+
    "number of columns ("+oSettings.aoColumns.length+")" );
    oSettings.iDrawError = oSettings.iDraw;
    return -1;
    }

    [/code]

    Again, thanks for any help you can provide.

    pbr
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    It seems like the reference to the settings object has been lost for whatever reason. Do you call any DataTables functions (on oTable) after you call fnDestroy? Do you re-initialise the table after the destroy is called? Might it be easier just to use fnClearTable to empty it out and then add your new data?

    Allan
  • pbrstreetgangpbrstreetgang Posts: 6Questions: 0Answers: 0
    Allan-

    I switched the fnDestroy() to fnClearTable() and everything worked great. I guess I was not reinitializing the table after destruction it.
    Thanks for your help, and great work on this plug-in.

    pbr
This discussion has been closed.