SelectableListTableContentProvider header order

Hello,

I have a SelectableListTableContentProvider that the user can sort all values by selecting on headers, like this image (header1.png)

How can I restart this sorting, using a button action? I tried to set all values null or empty, but i got exception.

Thanks!

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);
			}
		}
	}
}
2 Likes

Eric, thanks for reply.

No, I just want to set the header for original status. The values I will call a refresh action on my connector.

Thanks!

I’m not following what you are saying.

Can you provide any additional details?

Sure.

Looking at the image, the user sorted all table values selecting on header.

Now, I have an action button that needs to clean this header selection and clean all values in table.

To clean all values that’s ok, but I don’t know how to clean the header selection.

Thanks!

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.

I have put this code on the onClick action Button and didn’t work, the button have no more action

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.

2 Likes

It worked!!!

Thank you, Eric!

Eric, can I ask you one more thing?

It’s possible to select none values on table?

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”.

Thanks

Sure. From the server-side java code, get your table content provider and call the API to set the selected row ids to an empty collection.

For example:


tableProvider.setRowSelectedIds(Collections.emptyList());

Or from client-side script code, get your table model and call the API to unselect all items :


var tableModel = CAF.model('#{caf:cid("yourTableId")}');
tableModel.selectNone();

References:

  1. http://techcommunity.softwareag.com/ecosystem/documentation/webmethods/wmsuites/wmsuite9-9/My_webMethods/9-9_CAF_and_MWS_Java_API_Reference/com/webmethods/caf/faces/data/ISelectableTableContentProvider.html#setRowSelectedIds(java.util.Collection)

  2. http://techcommunity.softwareag.com/ecosystem/documentation/webmethods/wmsuites/wmsuite9-9/My_webMethods/9-9_CAF_JavaScript_Reference/CAF.Table.Model.html

2 Likes

Hi Luis,

You can set the selected row ids to null using the table provider as shown below:

getTableResultProvider().setRowSelectedIds(null);
1 Like

It worked!
Thank you Eric and Prasad!!