Sort column by label

Hi,

The layout I am using sorts columns by field just fine.

I have labels on the same layout. The labels display employee names from a different table. I would like to sort the columns alphabetically by the names displayed in the labels.

Here is the code I am using to sort the fields:

// Sort ascending to descending
var test = application.getMethodTriggerElementName(); // create variable to test against using ==
if (test == “entity”){
if (globals.gSort)
{
controller.sort(‘ss_entity asc’);
globals.gSort = null
}
else
{
controller.sort(‘ss_entity desc’);
globals.gSort = 1
}
}

I have tried the same code to sort by label but it does not work.

Is it possible to sort a column by a label? Thank you in advance.

Matt

You cannot sort of the text of labels, but you can sort on the underlying dataprovider (assuming your label displays a dataprovider).

When the dataprovider is an unstored calculation, you have to script the sort yourself though, because sorting on unstored calculations is not possible.

Paul

Paul,

Thank you for the response. That worked perfectly.

Matt

Paul,

I guess I spoke to soon about the solution working.

I have switched the label back to a field. This shouldn’t have any bearing on being able to sort I believe.

Here is an example of what my layout looks like:

Entity___CC____Level 1
30_____123____Joe Smith
20_____321____Aaron Williams

When I click on Entity and CC it sorts the column numerically

When I click on Level 1 to invoke the sort script instead of sorting, the entire table of values disappears.

The headings of the columns remain of course.

Entity CC Level 1

“No Data”

Is their a different way to script the sort based on calcs? I have been told previously that it is generally not good practice to manipulate the UI with a calc. Although once the calc is stored the ability to use the field on the layout instead of the calc is not an option.

Here is the calc I am using to display the field value

var emp1 = emp_cost_to_emp.first_name + " " + emp_cost_to_emp.last_name;
return emp1;

Matt

I’m not quite understanding what you setup is.

You have a Form in TableView in which you have a column based on a calculation that does:

var emp1 = emp_cost_to_emp.first_name + " " + emp_cost_to_emp.last_name;
return emp1;

Right?

Is the Calc stored or unstored?

Have you got a custom onSortCmd attached to that column? If so, what does it look like?

Paul

The calc pulls the column first name and last name from the emp_cost table and places it in the layout in which I am trying to sort.

The form is a List view. Each one of the column headers (i.e. Entity, CC, Level 1) are Label/Button

The calc is stored.

From what you describe, it sounds like it should work correctly. Can you post a sample displaying this behavior?

Paul

Unfortunately since I am at work I can’t post a sample. I will try to post one this evening.

Matt

Just realized I can add an attachment to a post. :oops:

Matt