Refresh datatables with jsf
Refresh datatables with jsf
Hi!
First of all, thank you for the plugin! It's been really useful :)
But I'm facing a problem: I'm trying to refresh a table using h:dataTable with JavaServer Faces. I've tried many different ways and none of them worked. I tried to delete and build the table again, I tried to use the draw() function, fnReloadAjax(), etc and I got many different errors.
Is there a way to reload a jsf table without passing the data in dataTables constructor? I'm building the table this way:
table = $('#table').DataTable({
"pagingType": "full_numbers",
"order": [[3, "desc"]]
});
And my table is like this:
<h:dataTable id="table" value="#{bean.data}" var="dt" > .... </h:dataTable>
Any help is appreciated!
Thanks!
This question has an accepted answers - jump to answer
Answers
If you mean that you want to refresh your table using f:ajax , then know that you have to re-init datatable upon ajax success
I mean something like this:
and add to your f:ajax the following:
And also take a look at this answer: http://stackoverflow.com/a/13747083/617373
Hi, Daniel!
Thanks for your reply. But I didn't understand what is the data format I have to pass. Is it json? Because I get from the managedBean a list of objects and I just pass it to the <h:dataTable>.
I tried to reload my jsf component but then it loses all the DataTables formatting. So I cannot simple reload my jsf component.
What I'm doing now is (and now it's almost working but not yet the way I wish), I refresh my component and then I initialize the DataTables. But I thought it might have some function in DataTable api that does it.
Thank you!
1) You can generate a simple (blank) table with <h:dataTable> and than load its content with ajax source ( create a servlet that will pass JSON to your table and from that moment work only with Datatable API ,
2) You really can load the entire table using the JSF and then apply Datatable API on it , choose what ever fit you best, but know that if it gonna be a really big table and you'll see performance issues, then you better do the first option I meantioned
I got it! I'll try the first option you mentioned. Thank you, Daniel!