Sunday, 8 September 2013

Primefaces datatables real-time polling

Primefaces datatables real-time polling

I have a JSF datatable equppied with http://www.datatables.net/ plugin. It
looks like this:
<h:form id="form">
<h:dataTable value="#{seedPageController.seedPages}"
var="dataTableItem"
styleClass="table table-condensed table-hover
table-bordered"
id="seedPagesTable">
<h:column>
<f:facet name="header">
<h:outputText value="ID" />
</f:facet>
<h:outputText value="#{dataTableItem.id}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="URL" />
</f:facet>
<h:outputLink
value="#{dataTableItem.url}">#{dataTableItem.url}</h:outputLink>
</h:column>
</h:dataTable>
</h:form>
</f:view>
<h:outputScript library="js" name="datatables-1.9.4.min.js" />
<h:outputScript library="js" name="paging.js" />
<script type="text/javascript">
$(document).ready(function() {
$("#form\\:seedPagesTable").dataTable({
"sDom":
"&lt;'row'&lt;'span4'l&gt;&lt;'span8'f&gt;r&gt;t&lt;'row'&lt;'span8'i&gt;&lt;'span8'p&gt;&gt;",
"sPaginationType": "bootstrap"
});
});
$.extend( $.fn.dataTableExt.oStdClasses, {
"sSortAsc": "header headerSortDown",
"sSortDesc": "header headerSortUp",
"sSortable": "header"
} );
</script>
The application is performing real-time polling repopulating the datatable
each second
<h:form>
<p:poll id="queue_poll" interval="1" update=":queue:seedPages,
:form:seedPagesTable, :queue:currentStatus"/>
</h:form>
Therefore the state of filters and sorting is lost. How to
repopulate/reinitialize the table with each Ajax call?

No comments:

Post a Comment