You would want to find the column controls and set the ordinal and ascending properties appropriately.
For example, something like this:
UIComponent component = findComponentInRoot("tableIdHere");
if (component instanceof UIData) {
UIData dataTable = (UIData)component;
//the column to make the primary sort column
String idToSortBy = "columnIdHere";
//which direction to order by
boolean isAscending = true;
for (Iterator<UIComponent> it = dataTable.getChildren().iterator(); it.hasNext();) {
UIComponent child = it.next();
if (child instanceof IExtendedColumn) {
IExtendedColumn column = (IExtendedColumn)child;
if (idToSortBy.equals(child.getId())) {
//make this the primary sort column
column.setOrdinal(1);
column.setAscending(isAscending);
} else {
//don't sort by this column
column.setOrdinal(0);
}
}
}
}
That’s basically what the snippet I provided does. It will reset the sort/order state of the columns to make one of the columns the primary sort column and clear any sort state from the other columns.
The code snippet I provided is server side java code that could be run in the action handler method for a command button.
The onClick value for a button is client-side javascript. The column sort state can not be changed for multiple columns at the same time from javascript.
For example, I have selected some lines using checkbox, when I click on action button, all checkboxes needs to be cleared, like when I click on select none on “Select all rows checkbox”.