Sort by stored calc

Hi everyone,

I posted recently about trying to sort columns based on a calculation. I have since added a column to the table to store the calculation. Here is the code that I am using to sort the column:

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

When I click on “level_1” which is the column heading to sort based on the data in level 1 the entire table disappears. I have to then click Show All to refresh the table.

Here also is the calculation for cName1:

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

I also thought by storing the calc the data would be present in the column in which it was being stored. For some reason nothing appears in the column. Data however does display in the calc field.

Thank you again for all your help.

Matt

Storing a calculation should result in the value being saved when the record is updated. Note that the value in the database can get “stale” if the calculation relies on data that might change outside the context of that record getting updated (if that makes sense).

Also, column names must be lowercase, and to store a calc it’s name must exactly match the column name. It should be considered a bug in servoy that the “stored calc” check will show checked when there’s a mis-match of case. I’m guessing your calc is name “cName1” and should be “cname1.”

Also, it’s generally considered bad form to try to manipulate the UI (ie call form/controller methods) from a calculation. Because you will often get odd results.

greg.

Thank you for the reply Greg. I understand what you are saying. I changed the case so it is storing properly now.

Now I am not able to add the column “cname1” to the layout. I have the option when adding new field or changing the data provider to add the calc.

I would just like to be able to sort the column based on the data displayed from cname1.

Is this possible?

Matt