tags:

views:

158

answers:

2

Can we sort values in column of a panelGrid. If yes, can I see an example

+1  A: 

No, you can't. <h:panelGrid> = <table>

If you want sorting, look at Richfaces or another component framework (Icefaces, primefaces, trinidad, tomahawk, etc). There are <x:dataTable> components there which allow sorting on their <x:colum>.

Bozho
Even in those cases, you're usually sorting on a DataTable. PanelGrids are used primarily for layout.
Drew
that's what I meant, yes. I'll update to clarify.
Bozho
+2  A: 

Rather use h:dataTable to represent a dynamic table which is backed by a List<RowObject>, wherein RowObject is basically just a Javabean (DTO - Data Transfer Obejct, VO - Value Object, whatever you call it :) ) representing a single row.

Such a List can be sorted using Collections#sort(). All you need to do is to implement a Comparator which takes care about the ordering. Then in the JSF page just have a bunch of buttons or links which calls Collections#sort() on the List. Those buttons/links just have to pass the sortfield along.

You can find here a basic example: http://balusc.blogspot.com/2006/06/using-datatables.html#SortingDatatable

BalusC