fnAddData - Prepend?
fnAddData - Prepend?
Daveomania
Posts: 15Questions: 0Answers: 0
Hello!
I am using the fnAddData call as follows:
[code]oTable.fnAddData(["SomeData", "SomeMoreData"]);[/code]
In a datatable which I set up as follows:
[code]oTable = $("[ID$=gvComments]").dataTable({
"sPaginationType": "full_numbers",
"iDisplayLength": 5,
"bFilter": false,
"bInfo": false,
"bLengthChange": false,
"aaSorting": []
});[/code]
I am wondering, how I can use this method and have my data prepended to my table instead of always on the last page, last row?
Thank you very much!
I am using the fnAddData call as follows:
[code]oTable.fnAddData(["SomeData", "SomeMoreData"]);[/code]
In a datatable which I set up as follows:
[code]oTable = $("[ID$=gvComments]").dataTable({
"sPaginationType": "full_numbers",
"iDisplayLength": 5,
"bFilter": false,
"bInfo": false,
"bLengthChange": false,
"aaSorting": []
});[/code]
I am wondering, how I can use this method and have my data prepended to my table instead of always on the last page, last row?
Thank you very much!
This discussion has been closed.
Replies
So the "fix" is to ensure the ordering is what you want in terms of your data.
Allan
The data is being sorted when pulled form the db and then dynamically built into a table prior to dataTable being applied.. but I think if I just add a hidden field with the appropriate data to sort in each column, I should be able to make this work!
I appreciate the response! :)
Allan
Thanks for the recent suggestion. It appears as though the standard sorting is working just fine. However I have come across a new issue which might just be on my part and not knowing the API fully.
When I dynamically add a row to the table via fnAddDate I then use fnDraw to re-initialize the table. This works perfectly. I also have functionality in the table to delete rows using fnDeleteRow(tr) where tr is the current row. This also works perfectly.
The problem arises when I use fnAddData, and then use fnDeleteRow on the newly added row. At this point, fnDeleteRow will remove the next row.
Any thoughts? Was my post confusing? lol
Example: [code]var tr = $(this).closest('tr').get(0);
oTable.fnDeleteRow(tr);[/code]
That solved my issue with the wrong node being removed in the mark-up. :)
[code]
var tr = $(this).closest('tr')[0];
oTable.fnDeleteRow(tr);
[/code]
fnDeleteRow expects a node, not a jQuery object.
This is on the radar for change in DataTables 1.10 or 1.11 when I get there :-)
Allan