weird error - fnAddData is not a function

weird error - fnAddData is not a function

mamadymamady Posts: 5Questions: 2Answers: 0
edited January 2012 in DataTables 1.8
I am getting a weird error where the dataTable() function seems to not return the correct object (I think?).

I have tried it with 1.8.2 and 1.9 - both give the exact same results.

I cant run any functions on the return value of dataTable(). For example, the below code fails:

[code]
var rTable = $('#reportdata').dataTable({
"oLanguage": {
"sEmptyTable": "No broken links found...",
"sLengthMenu": "Show entries: _MENU_"
},
"sDom": '<"top"lf<"clear">>rt<"actions"<"actions-left"i><"actions-right"p>>',
"sPaginationType": "full_numbers"
});

rTable.fnDestroy();
[/code]

The error firebug gives me is:

rTable.fnDestroy is not a function

The table itself is rendering fine, but when I try to use any function on it, I cant. The only one i really need is fnAddData() so I can add rows.

Any thoughts on this? I have been pulling my hair out for about 7 hours now. I suspect it's a fault on my end, Im just wondering if anyone else has come across this before?

Replies

  • allanallan Posts: 61,880Questions: 1Answers: 10,139 Site admin
    Very odd. This would be caught by the unit tests if there was a problem with returning the instance, and it does appear to work as expected for me: http://live.datatables.net/ekesen/edit .

    Can you link to your demo page that shows the problem please?

    Allan
  • mamadymamady Posts: 5Questions: 2Answers: 0
    I figured it would be an issue on my end, I was hoping for some clues from others that may have run into this issue.

    Just for anyone else that comes across this in the future...

    The issue was that there is some type of clash between my other javascript libraries and datatables. I dont know which other js lib was causing the problem (I am using quite a few), but the fix was to move the datatables.js include file to be the last file that is loaded - this fixed the problem. No js code changes needed!

    Alan, I speak for everyone when I say your support is awesome. Thank you so much. Some of us thank you in silence, others thank you explicitly; but everyone appreciates your great support.

    Thanks again.
  • allanallan Posts: 61,880Questions: 1Answers: 10,139 Site admin
    Thanks for your kind words :-)

    Thanks for posting your findings! It sounds like you might have loaded jQuery twice. If you do:

    1. jQuery
    2. DataTables
    3. jQuery

    The second jQuery will overwrite the first one (which has DataTables attached to it). Thus you would end up with a jQuery object that doesn't have DataTables available.

    Bit frustrating that jQuery doesn't give an error about being loaded twice as it bites a lot of people (me included), but, so it goes...

    Allan
This discussion has been closed.