Hi,
I would like show/hide some table’s columns clicking on one header column.
I tried using “one way toggle link” but I can show/hide only one column (single control). I tried to set more than one controls in “for” property of “one way toggle link” setting the controls with comma as separator.
All the columns have “Allow Toggle” property setted true.
How can I use the toggle feature to show/hide more than one columns (multiple controls) ?
I believe the “one way toggle” controls only support one control id in the “for” property.
You could probably solve the problem by using an “Async Command Link” instead. Inside the java code of your command handler, you can change the value of the ‘Rendered’ field of the columns you don’t want to render.
When the table redraws after the async command runs, the columns you chose not to render would no longer be there.
Hi Eric,
thanks for advice.
It works fine. My requirement is to put this “async command link” as a column’s header of the table, but when I click the link I lost the sort feature.
There is a way to put one text and one link in the same header’s column to have the both the feature?
Thanks
Bye
Fabio
Perhaps your command handler java code could update the sort column as well.
For example, invoke something like this:
/**
* Update the table sort details
* @param dataTable the table control to process
* @param sortByColumnId the id of the column to sort by
* @param sortAscending true for ascending sort order, false for descending
*/
protected void changeSortColumn(UIData dataTable, String sortByColumnId, boolean sortAscending) {
if (dataTable != null) {
//loop through all the columns and configure which one to sort by
for (Iterator<UIComponent> it = dataTable.getChildren().iterator(); it.hasNext();) {
UIComponent child = it.next();
if (child instanceof IExtendedColumn) {
//fix sort/order
if (StringTools.notEmpty(sortByColumnId)) {
if (child.getId() != null && child.getId().equals(sortByColumnId)) {
//this is the sort column, so set-up the sorting
((IExtendedColumn)child).setOrdinal(1);
((IExtendedColumn)child).setAscending(sortAscending);
} else {
//not sorting by this column, so clear the ordinal
((IExtendedColumn)child).setOrdinal(0);
}
}
}
}
}
}