fnDraw after fnGetNodes

fnDraw after fnGetNodes

SimonRSimonR Posts: 10Questions: 0Answers: 0
edited May 2013 in Bug reports
Hi all,
Not really sure this is a bug, I looked on the forum before and couldn't find a duplicate so here it is:
I'm using Datatables 1.9.4 mostly to decorate my tables, bit of pagination, filtering, etc.

Some of those table have input field in them that I wish to be able to post using a regular form, problem is with the pagination not all the rows are posted since not all the rows exist in the DOM, that's not the problem mind you.

To counter that I simply moved the tables out of their respective forms and added an hidden table inside the forms, a bit of extra javascript :
[code]
$('#SaveForm').submit(function () {
$('#hiddenTable', this).append(oTable.fnGetNodes());
return true;
});
[/code]
And badaboom problem solved I have all my data server-side, now the problem is that some of the server side operation take some time and that fnGetNodes() empty the displayed table, since I doesn't look too nice I simply decided to redrew the table by using fnDraw() after fnGetNodes() so the table would stay visible while waiting for the operation to finish.

Now if I do that, fnDraw() will actually destroy the rows in my hiddenTable ! Leaving me with no data to post, and an ASP DefaultModelBinder laughing at my face !

So here you have it, I think it's kind of a double bug :
- fnGetNodes emptying the table
- fnDraw destroying DOM objects outside the the original table

A test bellow shows the problem, seems that only the data that will be displayed in the table will be destroyed in the hiddenTable
http://live.datatables.net/ujemey

I added a confirm between the fnGetNodes() and the fnDraw() to pause the process

PS : It might be my fault, if that's the case sorry about that, I'm fairly new to JS/JQ/Datatable

Replies

  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    > Now if I do that, fnDraw() will actually destroy the rows in my hiddenTable

    It doesn't destroy them. It redraws them into the DataTable - which is what you've asked it to do :-).

    At best you could try cloning the nodes, but in some browsers you'll lose the user entered value. The other option might be to have DataTables draw all rows, or perhaps use Ajax.

    Allan
  • SimonRSimonR Posts: 10Questions: 0Answers: 0
    I don't see how it makes sense that datatables affect DOM elements outside the original table ?
    Does datatables offer a clean method to clone all the nodes that I could use instead of fnGetNodes ?
  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    They are the same DOM elements. If you move them somewhere else, then it will move them out of the table. If you redraw the table, it will move them back in (if there are needed for the draw). They aren't cloned by DataTables core and DataTables doesn't know you've moved them somewhere else.

    If you want to clone the nodes, you could just use `$( table.fnGetNodes() ).clone()` - but as I say, watch out for some browsers which will lose the value (IE).

    Allan
  • SimonRSimonR Posts: 10Questions: 0Answers: 0
    edited May 2013
    urg yeah, forgot the problem with DOM elements and their unique ids, a semantic problem on my side.
    Well empty table it is then, or I could ajaxify everything I guess.
    Thanks Allan
This discussion has been closed.