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

妖精的绣舞 提交于 2019-12-11 12:52:14

问题


I am studying tomahawk, I just want to know if I generate a datatable using <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.


回答1:


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.




回答2:


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">


来源:https://stackoverflow.com/questions/2522341/how-to-sort-a-data-table-if-we-are-using-tcolumns-in-jsf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!