开发者

How to sort a data table if we are using <t:columns> in JSF?

I am studying tomahawk, I just want to know if I generate a datatable usin开发者_StackOverflow中文版g <t:columns> then how to sort the dataTable on the click on the header of that particular column, like we are using <t:commandSortHeader> in normal <t:column> attribute. Kindly Help.


Using a t:datatable you don't really need the t:commandSortHeader, unless you want to customise what property it uses to sort.

Here is what you need to get this working:

<h:form>
<t:dataTable
    id="data"
    value="#{BACKINGBEAN.DATA}"
    var="item"
    sortColumn="#{BACKINGBEAN.sortColumn}"
            sortAscending="#{BACKINGBEAN.sortAscending}">

...

<t:column defaultSorted="true" sortable="true">
    <f:facet name="header">
             <h:outputText value="header text"/>
    </f:facet>
    <h:outputText value="#{item.property}" />
</t:column>

...

</t:dataTable>
</h:form>

Then in your backing bean:

private String sortColumn;
private boolean sortAscending;

with default getters/setters/lombok. They are just so the tag can set data.

This is a great reference: http://wiki.apache.org/myfaces/Working_with_auto_sortable_tables

But it misses the discussion about the backing bean properties, plus that it needs to be wrapped in a <h:form> even if you dont have any form elements.


One possibility is to use jQuery plugin sort. Look here

The other is to use t:dataTable together with t:commandSortHeader as you have described

<t:dataTable  
id="data"  
value="#{BACKINGBEAN.DATA}"  
var="item"  
...  
sortable="true"
rows="10">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜