voyent
Multiple Column Sorting in DataTable  XML
Forum Index -> Components
Author Message
Tracker09

Joined: 12/May/2008 00:00:00
Messages: 14
Offline


Woodstock came with the ability to sort on multiple columns. Meaning if one column is sorted, you could click on an additional column and have the values of that column subsorted. This does not seem to be supported in IceFaces. Is there way to accomplish this. I see there was a feature request for such functionality that was never implemented.
mkat

Joined: 16/Oct/2008 00:00:00
Messages: 96
Offline


I've used single column sorting in icefaces, but I've never tried multiple. It seems like it should be possible with the built in icefaces sortableColumn stuff.

Otherwise, assuming you are using a dataTable loading data from a db, you could implement multicolumn sorting like this:

Have each column's header be clickable (a button or link) and with each click toggle a boolean or other value in the backing.

Based on those values, build an "ORDER BY" string to tack onto the end of the query being used to generate the list for your table.

That's one idea anyway...

maruthy

Joined: 30/Jun/2009 00:00:00
Messages: 28
Offline


Hi mkat could you please post the code snippet for single column sorting in icefaces.

Thanks!
Maruthy...
sparky_20

Joined: 07/Jan/2010 00:00:00
Messages: 19
Offline


@maruthy

Single sort code:

Web page:

<ice:dataTable id="eventTable"
rows="#{bean.numberOfRowsToDisplay}"
value="#{bean.dataList}" var="item"
sortColumn="#{bean.sortColumnName}"
sortAscending="#{bean.ascending}">
<ice:column>
<f:facet name="header">
<ice:commandSortHeader actionListener="#{bean.sortTable}"
columnName="#{bundle.contractName}" arrow="true" >
<ice:outputText value="#{bundle.columnTitle}" />
</ice:commandSortHeader>
</f:facet>
<ice:outputText value="#{bundle.columnText}" />
</ice:column>
.......
</ice:dataTable>


Backing bean:

public void sortTable(ActionEvent event) {
if (event != null && !event.getPhaseId().equals(PhaseId.INVOKE_APPLICATION)) {
event.setPhaseId(PhaseId.INVOKE_APPLICATION);
event.queue();
return;
}

// Create a comparator based on your needs.
Comparator comparator = new Comparator() {
public int compare(Object o1, Object o2) {
ObjectRow e1 = (ObjectRow) o1;
ObjectRow e2 = (ObjectRow) o2;

if (sortColumnName == null) {
return 0;
}

if (sortColumnName.equals(getMessage("contractName"))) {
return ascending ? (e1.getName().compareTo(e2.getName()) == 0 ? e1.getEventDate()
.compareTo(e2.getEventDate()) : e1.getName().compareTo(e2.getName())) : (e2
.getName().compareTo(e1.getName()) == 0 ? e1.getEventDate().compareTo(
e2.getEventDate()) : e2.getName().compareTo(e1.getName()));
} else
return 0;
}
};
Collections.sort(dataList, comparator);
}


In the example given by me you can see that if the name value is the same, than an ordering is done based on the date. This is not multiple sorting because it is hardcoded (always done by date, ignoring the asceding).
 
Forum Index -> Components
Go to:   
Powered by JForum 2.1.7ice © JForum Team