You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by madan chowdary <ma...@yahoo.com> on 2007/03/29 11:45:14 UTC
[ Tobago ] Help Regarding Customer Sort in Sheet
Hi All,
I have a sheet which has a column to display the price of an item.
Used a convertor to display the price which converts the price( BigDecimal ) to a string and append the users currency set for the user.
Say ,if User currency set to US Dollar , then the price 245.06 (BigDecimal) would be displayed as such " US $245.06 ".
<tc:column label="Price" id="prdPrice" align="right">
<tc:out value="#{searchItem}" id="p_price" converter="PriceConverter" escape="false"
markup="sheetTxt"/>
</tc:column>
This is being displayed as String in the Price Column in the sheet.
If i use sortable="true" for this column, there is no sorting done according to the price as its sorting String wise but not in numerics.
So i shud use a custom sort for this , if there is no other means.
Can anyone explain me how can i do such sort capability in the sheet , with an example code.
Regards,
Madan
__________________________________________________________
Yahoo! India Answers: Share what you know. Learn something new
http://in.answers.yahoo.com/
Re: [ Tobago ] Help Regarding Customer Sort in Sheet
Posted by Volker Weber <v....@inexso.de>.
Hi Madan,
here the relevant part of one of my apps, you need to define the comparators:
use the sortActionListener attribute of the tc:sheet tag.
<tc:sheet ... value="#{bean.list}" sortActionListener="#{bean.sortSheet}">...
than this actionListener method si completely responsible for sorting,
the sheet itself dosent sort anymore.
public void sortSheet(ActionEvent event) throws ErmException {
if (event instanceof SortActionEvent) {
SortActionEvent sortEvent = (SortActionEvent) event;
UIColumn column = sortEvent.getColumn();
String columnId = column.getId();
if ("rTime".equals(columnId)) {
Collections.sort(list, rTimeComparator);
} else if ("state".equals(columnId)) {
Collections.sort(list, stateComparator);
} else if ("mailbox".equals(columnId)) {
Collections.sort(list, mailboxComparator);
} else if ("subject".equals(columnId)) {
Collections.sort(list, subjectComparator);
} else if ("address".equals(columnId)) {
Collections.sort(list, addressComparator);
} else if ("mailId".equals(columnId)) {
Collections.sort(list, mailIdComparator);
} else if ("location".equals(columnId)) {
Collections.sort(list, locationComparator);
} else if ("date".equals(columnId)) {
Collections.sort(list, dateComparator);
} else if ("pending".equals(columnId)) {
Collections.sort(list, pendingComparator);
} else if ("duration".equals(columnId)) {
Collections.sort(list, durationComparator);
} else {
LOG.error("Unsupported columnId : " + columnId);
return;
}
SheetState sheetState =
sortEvent.getSheet().getSheetState(FacesContext.getCurrentInstance());
if (!sheetState.isAscending()) {
Collections.reverse(list);
}
}
}
Regards,
Volker
2007/3/29, madan chowdary <ma...@yahoo.com>:
>
> Hi All,
>
> I have a sheet which has a column to display the price of an item.
>
> Used a convertor to display the price which converts the price( BigDecimal )
> to a string and append the users currency set for the user.
>
> Say ,if User currency set to US Dollar , then the price 245.06 (BigDecimal)
> would be displayed as such " US $245.06 ".
>
> <tc:column label="Price" id="prdPrice" align="right">
> <tc:out value="#{searchItem}" id="p_price" converter="PriceConverter"
> escape="false"
> markup="sheetTxt"/>
> </tc:column>
>
>
> This is being displayed as String in the Price Column in the sheet.
>
> If i use sortable="true" for this column, there is no sorting done according
> to the price as its sorting String wise but not in numerics.
>
> So i shud use a custom sort for this , if there is no other means.
>
> Can anyone explain me how can i do such sort capability in the sheet , with
> an example code.
>
> Regards,
> Madan
>
> ________________________________
> Here's a new way to find what you're looking for - Yahoo! Answers