Getting error when adding rows as jQuery instance
Getting error when adding rows as jQuery instance
I load DataTables on page which already have HTML table and search engine,
Search engine submit data via ajax and retrieve it to DataTables through clearing data then add rows, but I got this error:
DataTables warning: table id=students - Requested unknown parameter '1' for row 0. For more information about this error, please see http://datatables.net/tn/4
And I got this strings in my table for each row:
[object HTMLTableRowElement]
It works good when I'm using row.add()
like this:
var jRow1 = $('<tr>').append('<td><a href="./viewstudent.php?id=150">150</a></td>',
'<td>Yasser Moustafa Lotfy</td>',
'<td>Website</td>',
'<td><b>Language</b>: English, <b>Institution</b>: <a href="./viewinst.php?id=539">Australian Language Schools - ALS</a>, AUS<br><b>Bachelor</b>: Art, <b>Institution</b>: <a href="./viewinst.php?id=1">Australian National University (ANU)</a>, AUS<br><b>Master</b>: Information Technology, <b>Institution (None KPI)</b>: Test University, USA<br><b>Master</b>: MBA, <b>Institution</b>: <a href="./viewinst.php?id=175">Pace University</a>, USA<br></td>',
'<td class="hint--left hint--rounded hint--tbl--big" data-hint="Last Update: تم التواصل معك على هذا الرقم ولم يتم الرد، الرجاء التواصل معنا على الرقم 0126136080 في أقرب وقت.">Active</td>',
'<td><a href="./viewuser.php?id=2">Ibrahim Alzahrani</a></td>',
'<td class="text-center"><a class="table-action" href="./viewstudent.php?id=150"> <i class="fa fa-external-link"></i></a><a class="table-action" href="./editstudent.php?id=150"> <i class="fa fa-pencil-square-o"></i></a><a class="table-action" href="./deletestudent.php?id=150"> <i class="fa fa-trash-o"></i></a></td>');
table.row.add(jRow1).draw();
But not working when I'm using rows.add()
like this:
table.rows.add([
$('<tr>').append('<td><a href="./viewstudent.php?id=150">150</a></td>',
'<td>Yasser Moustafa Lotfy</td>',
'<td>Website</td>',
'<td><b>Language</b>: English, <b>Institution</b>: <a href="./viewinst.php?id=539">Australian Language Schools - ALS</a>, AUS<br><b>Bachelor</b>: Art, <b>Institution</b>: <a href="./viewinst.php?id=1">Australian National University (ANU)</a>, AUS<br><b>Master</b>: Information Technology, <b>Institution (None KPI)</b>: Test University, USA<br><b>Master</b>: MBA, <b>Institution</b>: <a href="./viewinst.php?id=175">Pace University</a>, USA<br></td>',
'<td class="hint--left hint--rounded hint--tbl--big" data-hint="Last Update: تم التواصل معك على هذا الرقم ولم يتم الرد، الرجاء التواصل معنا على الرقم 0126136080 في أقرب وقت.">Active</td>',
'<td><a href="./viewuser.php?id=2">Ibrahim Alzahrani</a></td>',
'<td class="text-center"><a class="table-action" href="./viewstudent.php?id=150"> <i class="fa fa-external-link"></i></a><a class="table-action" href="./editstudent.php?id=150"> <i class="fa fa-pencil-square-o"></i></a><a class="table-action" href="./deletestudent.php?id=150"> <i class="fa fa-trash-o"></i></a></td>'),
$('<tr>').append('<td><a href="./viewstudent.php?id=151">151</a></td>',
'<td>Yasser Moustafa Lotfy</td>',
'<td>Website</td>',
'<td><b>Language</b>: English, <b>Institution</b>: <a href="./viewinst.php?id=539">Australian Language Schools - ALS</a>, AUS<br><b>Bachelor</b>: Art, <b>Institution</b>: <a href="./viewinst.php?id=1">Australian National University (ANU)</a>, AUS<br><b>Master</b>: Information Technology, <b>Institution (None KPI)</b>: Test University, USA<br><b>Master</b>: MBA, <b>Institution</b>: <a href="./viewinst.php?id=175">Pace University</a>, USA<br></td>',
'<td class="hint--left hint--rounded hint--tbl--big" data-hint="Last Update: تم التواصل معك على هذا الرقم ولم يتم الرد، الرجاء التواصل معنا على الرقم 0126136080 في أقرب وقت.">Active</td>',
'<td><a href="./viewuser.php?id=2">Ibrahim Alzahrani</a></td>',
'<td class="text-center"><a class="table-action" href="./viewstudent.php?id=150"> <i class="fa fa-external-link"></i></a><a class="table-action" href="./editstudent.php?id=150"> <i class="fa fa-pencil-square-o"></i></a><a class="table-action" href="./deletestudent.php?id=150"> <i class="fa fa-trash-o"></i></a></td>')
]).draw();
Could you please help me to fix it !
And Thanks for this great plugin.
This question has an accepted answers - jump to answer
Answers
Is it very difficult !
Please help me getting rid o it.
I have fixed it by using this method:
Please update documentation for
row.add()
androws.add()
for this method because it's not mentioned there.Actually, I would have expected your original code to have works. Can you check you are using 1.10.9 (I seem to recall in issue about this in earlier 1.10 versions, I think), and if that doesn't help, link to a test case showing the issue please?
Thanks,
Allan
I was working on 1.10.9 and it was not working
Thank you for the confirmation. I've made a trivial test case here: http://live.datatables.net/xevohagu/1/edit .
Passing the node in works okay, but passing a jQuery object in - not so much.
I'll look into this and post a fix.
Thanks,
Allan
I'm not profissional in js.
what is the meaning of the
[0]
at end of first row insiderows.add()
?if I added this
[0]
at end of each row insiderows.add()
it will work smoothly like ThisIt just gets the node. jQuery is "array like" (i.e. it looks like an array, but isn't actually one) and it contains the DOM elements that have been selected or created. So in this case it get the node at "array" index 0 (since that is where jQuery puts it when it creates an element).
That shouldn't be needed though - this is a bug.
Allan