问题
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