I'm trying to add data to a table dynamically through JavaScript, and it returns this:
Uncaught TypeError: Cannot read property 'add' of undefined.
EDIT: The code works perfectly without the row.add line.
Relevant code:
<html>
<head>
<link rel="stylesheet" type="text/css" href="./css/jquery.dataTables.min.css">
<script type="text/javascript" src="./lib/jquery.min.js"></script>
<script type="text/javascript" src="./lib/jquery.dataTables.min.js"></script>
<script>
var dataSet = [
['1.1','2.1'],
['1.2','2.2'],
];
$(document).ready(function() {
$('#demo').html( '<table cellpadding="0" cellspacing="0" border="0" class="display" id="example"></table>' );
t = $('#example').dataTable(
{
data: dataSet,
columns: [
{ "title": "Col 1" },
{ "title": "Col 2" },
],
});
t.row.add(['1.3', '2.3']) // <-- Fails
});
</script>
</head>
<body>
<div id="demo" style="width:500px"> </div>
</body>
</html>
t.rowdeclared/initialized in your code