1

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.

Hariharbalaji
  • 2,498
  • 8
  • 36
  • 51

2 Answers2

2

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.

Steve Swinsburg
  • 592
  • 2
  • 14
  • The apache-wiki also does not mention this won't work when your bean is `@RequestScoped` – Joost Oct 08 '14 at 11:14
1

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">
Shervin Asgari
  • 23,901
  • 30
  • 103
  • 143
  • thanks for the for telling the possiblity in jQuery ,but wanted to try without it, my doubt is like even when if if put within the its getting sorted according to the first column only, and not with respective of individual column. – Hariharbalaji Mar 26 '10 at 17:38
  • Yes are you right. You will need to do this on the SQL side before you retrieve the list is my guess. You need to `order by some1 some2` – Shervin Asgari Mar 29 '10 at 07:48