client side datatable pagination in jsf

Hi,

if  you want to add simple client side pagination to a datatable in JSF, it is very simple to do so.

suppose you have this regular h:datatable in your page:

<h:dataTable id="datatable" var="item" value="#{someBean.all}">

<h:column>
<f:facet name="header">
<h:outputText value="my header"/>
</f:facet>
<h:outputText value="#{item.someField}" escape="true"/>
</h:column>

</h:datatable>

just use jQuery and use this plugin: http://neoalchemy.org/tablePagination.html

include the plugins and jQuery’s js in your page and just add this to your page:

jQuery(document).ready(function() {
jQuery('#datatable').tablePagination();
});

and that is all. It works for 1.2 and 2.0.

btw this thing is useful if you are not using PrimeFaces. PrimeFaces ease your custom needs very quickly. this solution is for a situation where you cannot use PrimeFaces some how.

Advertisements