2

In attempting to add a row to the jquery DataTable I am do the following:

//add new status row to the DataTable
$('#errorTable').dataTable().fnAddData( [
     id,
     msg,
     tm
]);

I used to use the code below table.row.add([...]) to add a row - and it did work for awhile however all of the sudden it is giving me the following error:

Unhandled exception at line 102, column 17 in http://127.0.0.1:45319/js/errors.js?v=3

0x800a138f - JavaScript runtime error: Unable to get property 'add' of undefined or null reference

var table = $('#errorTable').dataTable();
table.row.add([
    id,
    msg,
    tm
]).draw();

In fact doesn't the jQuery documentation use the table.row.add code in it's own example. My question is why doesn't it work and why does the fnAddData work? What am I missing or doing wrong?

1 Answer 1

3

Use DataTable() to get access to newer API methods introduced in version 1.10+. For example:

var table = $('#errorTable').DataTable();
table.row.add([id, msg, tm]).draw();

You can continue using old API with dataTable(), for example:

$('#errorTable').dataTable().fnAddData([id,msg,tm]);
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Gyrocode - I didn't realize the difference between DataTable() and dataTable().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.