Sorting table views

I’m trying to get my tableviews to sort correctly. I’ve added a onSort method to my form to handle sorting my columns:

function onSort(dataProviderID, asc, event) 
{
	if(!dataProviderID) return;
	switch (dataProviderID) {
		case 'call_fullnumber':
			foundset.sort('call_nr '+ (asc ? ' asc' : ' desc')+','+dataProviderID + (asc ? ' asc' : ' desc'));
			break;
		case 'call_respempid':
			foundset.sort('calls_to_employees$resp.emp_firstname '+ (asc ? ' asc' : ' desc')+', calls_to_employees$resp.emp_lastname' + (asc ? ' asc' : ' desc'));
			break;
		case 'call_principalid':
			foundset.sort('calls_to_principals.principal_name '+ (asc ? ' asc' : ' desc'));
			break;
		case "call_subcontractorid":
			foundset.sort('calls_to_subcontractors.subcontractor_name '+ (asc ? ' asc' : ' desc'));
			break;
		case 'call_state':
		case 'call_statetxt':
			foundset.sort('datfin ' + (asc ? ' asc' : ' desc')+', call_deadline ' + (asc ? ' asc' : ' desc'), false);
			break;
		case 'call_code':
			foundset.sort(sortCallCode)
			break;
		default:
			foundset.sort(dataProviderID + (asc ? ' asc' : ' desc'), false);
			break;
	}
}

These seem to work correcty except for the ‘call_code’ dataprovider. This field is linked to a valuelist and I tried added a sort function to hande the sort but it does only sort one way. And also the column does not receive the sort marker in the header (black triangle).
This is my valuelist sort function:

function sortCallCode(r1,r2) {
	return valuelistSort(r1.call_code, r2.call_code, 'pronto_callcode');
}

/**
 * @param {number} r1 first value
 * @param {number} r2 second value
 * @param {String} vl Valuelist name
 * @return {Number}
 * 
 * @properties={typeid:24,uuid:"E7619471-21ED-40A0-97CE-D49BF677624B"}
 */
function valuelistSort(r1,r2,vl) {
	var o = 0;
	
	var v1 = application.getValueListDisplayValue(vl,r1);
	var v2 = application.getValueListDisplayValue(vl,r2);
	if(v1==null) v1='';
	if(v2==null) v2='';
	if(v1 < v2) {
		o = -1;
	}else if (v1 > v2) {
		o = 1;
	}
	return o;
}

any suggestions on what I’m doing wrong here?

Hi Jos,

to start with the easiest answer: the black triangle.
This is only displayed if the column you sort on has the same name as the column where it belongs to.
In this case they’re different, so no sort triangle (btw, did a feature request for this SVY-640)

your second problem: one way sort.
This is because the sort function only returns values based on a one-way sort.
Question: are the value list values available in a table? In case they are, go easy and make the column sort on these value by using a relation.

Hope this helps

Hi Marc,

A relation is not possible, because the value in my table is a number and the value in the valuelist table is a varchar (containing in this case only numbers)

jdbruijn:
A relation is not possible, because the value in my table is a number and the value in the valuelist table is a varchar (containing in this case only numbers)

As a workaround you can create an unstored calculation (text) and convert the number to text.
Then use this calculation as the primary dataprovider to base your relation on.

Not the nicest way, but it works…

Jos,

Why don’t you use the asc-argument of your onSort function in sortCallCode, like you do for the other columns?

Rob

rgansevles:
Jos,

Why don’t you use the asc-argument of your onSort function in sortCallCode, like you do for the other columns?

Rob

yep that was what i figured out yesterday.
According to the wiki it is not possible to pass that parameter to the recordComparisonFunction, so I’m using a global var for this now.
But wouldn’t it be easier to pass this directly to the recordComparisonFunction?

Jos,

The sort method needs a function, if you pass it a value and use brackets you are calling the function in stead of passing it to the sort method.

Rob