cancel
Showing results for 
Search instead for 
Did you mean: 

Table Sorter Sort on different table cell

former_member540174
Participant
0 Kudos

I have a table that is sorting fine using the TableSorter for 2004s. I now have a requirement to sort a column that contains a mixture of data - Clock Date/Time if it exists or words Absent and Date. Just sorting this column does not give the user the results required as they want all the dates sorted together regardless of the word Absent or not.

I have created another column that contains just the ClockDate/Time or the Absence Date/Time my assumption is that somehow I can get this column's data used instead of the data in the sort column.

Any guidance on how I can achieve this?

Regards, Diane

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member540174
Participant
0 Kudos

I copied the NodeElementByAttributeComparator in the TableSorter object and created another object called NodeElementByOtherAttributeComparator. There I changed the signature to include my additional attribute (this variable contains the columnId of the column to use. Then things started falling apart.

First I put the new object inside of the tablesorter object..... that was fine until I tried to include the comparator in the doModifyView. I have an error where I create the instance of my comparator (which is a class inside of TableSorter (like the NodeElementByAttributeComparator is.....

Error says "No enclosing instance of type TableSorter is accessable.

I'm obviously going wrong here - any guidance.


if (firstTime)
{
HashMap otherComparators  = new HashMap();
ArrayList methodAndKey = new ArrayList(Arrays.asList(new String[] { "NodeElementByOtherAttributeComparator", "ClockIn" } ) );	
NodeElementByOtherAttributeComparator sortByOtherAttributeComparator = new NodeElementByOtherAttributeComparator("ClockIn", "ClockInDT");
otherComparators.put("ClockIn",sortByOtherAttributeComparator);
wdContext.currentContextElement().setTableSorter(new TableSorter(table, wdThis.wdGetSortAction(),otherComparators,
  new String[] {"EmployeeName"
    ,"EmplId"
    ,"OrgDesc"
    ,"Shift" 
    ,"ClockIn"
}));
}

former_member540174
Participant
0 Kudos

When you say array of comparator objects in the call that assignes the table sorter to the table - so you mean to pass my comparator in the third parameter? in this case is the null?

wdContext.currentContextElement().setTableSorter(new TableSorter(table, wdThis.wdGetSortAction(),null,

new String[] {"EmployeeName"

,"EmplId"

,"OrgDesc"

,"Shift"

,"ClockIn" <=== This is the column I want to sort but the data from a different column ClockInDT

}));

When I look at the TableSorter that field is of type Map .

Any details or samples would be appreciated!

Regards,

Diane

Former Member
0 Kudos

Did you have a look at the TableSorter Javadoc?


	/**
	 * Creates a table sorter for the given table using the given sort action.
	 * This constructor must be called from <code>wdDoModifyView()</code>, but
	 * usually only when that hook is called for the first time. Store the newly
	 * created instance in a context attribute with Java native type
	 * <code>com.sap.tc.webdynpro.tests.utils.TableSorter</code>.
	 * The given sort action's event handler will be bound to the <code>onSort</code>
	 * event of the table and must at least call this table sorter's
	 * <code>sort(wdEvent)</code> method.
	 * 
	 * Every column of the table is made sortable if possible according to the
	 * following rules.
	 * If a comparator is given for a column's ID and it is a
	 * <code>NodeElementByAttributeComparator</code>, then that comparator defines
	 * both the attribute and the ordering used to sort that column.
	 * If any other comparator is given and an attribute can be determined from
	 * that column's table cell editor, then that attribute is used to sort that
	 * column according to the ordering imposed by the given comparator.
	 * If no comparator is given but an attribute can be determined from
	 * that column's table cell editor, then that attribute is used to sort that
	 * column according to the natural ordering of that attribute's type.
	 * Else that column is left untouched.
	 * 
	 * Additionally it is possible to define the sortable columns by their 
	 * TableColumn UI element ids.
	 * 
	 * @see sort()
	 * @see NodeElementByAttributeComparator
	 * @see com.sap.tc.webdynpro.clientserver.uielib.standard.api.IWDTable
	 */
	public TableSorter(IWDTable table, IWDAction sortAction, Map comparators) {
		init(table, sortAction, comparators, null);
	}

Create a suitable Comparator for your column, put it into a Map with key = TableColumn ID and pass the Map to the TableSorter constructor.

Armin

Former Member
0 Kudos

IIRC you can pass an array of Comparator objects in the call that assigns the table sorter to the table. There you could pass a Comparator that implements your sort order.

Armin