Redraw without changing page
Redraw without changing page
jaredcrossley
Posts: 8Questions: 0Answers: 0
What is the best way to redraw a table (as in fnDraw) without changing the current page? I found another discussion in the forum where it was suggested to set _iDisplayStart prior to calling fnDraw, but it appears to me that if the table has bSort or bFilter set to true, DataTables will reset _iDisplayStart to zero on each draw.
My table does have active sorting and filtering, but I want to allow the user to add/remove rows at a specific location without re-sorting and re-filtering on each add/remove.
I've found a way to do this...
[code]
oSettings.oFeatures.bFilter = false;
oSettings.oFeatures.bSort = false;
oDataTable.fnDraw();
oSettings.oFeatures.bFilter = true;
oSettings.oFeatures.bSort = true;
[/code]
but I'm wondering if there is a more elegant way?
Thanks,
Jared
My table does have active sorting and filtering, but I want to allow the user to add/remove rows at a specific location without re-sorting and re-filtering on each add/remove.
I've found a way to do this...
[code]
oSettings.oFeatures.bFilter = false;
oSettings.oFeatures.bSort = false;
oDataTable.fnDraw();
oSettings.oFeatures.bFilter = true;
oSettings.oFeatures.bSort = true;
[/code]
but I'm wondering if there is a more elegant way?
Thanks,
Jared
This discussion has been closed.
Replies
The reason this display is being reset is because DataTables is doing a resort and a refilter when fnDraw is called. For this the display is set back to zero. Your method for getting around it is quite a neat little solution, but could potentially cause issues in future versions of DataTables, since feature variables aren't dynamically switchable.
One way around it is presented here: http://datatables.net/forums/comments.php?DiscussionID=573 . Another way is to called the internal functions "_fnCalculateEnd( oSettings ); fnDraw( oSettings );" (in that order) which will not force a redraw or resort.
I might wrap the two functions above into an API call as this has come up a few times recently...
Regards,
Allan
I've just bashed together a plug-in API function which will accept a boolean argument to page forwards (true) or backwards (false) - fnPageChange() : http://datatables.net/plug-ins/api#fnPageChange :-)
Regards,
Allan
Thanks for your help with this. The two solutions you posted in your first reply are working for me. I'm not sure how to use the fnPageChange plug-in to solve my problem. I simply wanted to redraw the table without sorting and filtering. If I've misunderstood the purpose of the plugin, please let me know.
But again, both of your first two solutions work, so at the moment the plug-in is not necessary.
Thanks for your help!
Jared
oDataTable.fnDraw(false);
I encounter the same problem.I have resolved. Only take a parameter false.
[code] oDataTable.fnDraw(false);[/code]
I encounter the same problem.I have resolved. Only take a parameter false.