onSort method

I have an onSort method defined on my form.

This method only contains the following code:

var _form = application.getMethodTriggerFormName()
var _element = application.getMethodTriggerElementName()

When I press on the tableview header to sort the column, I see that this method is being called.
The triggered formname is filled correctly
The triggered elementname becomes null

Is this a bug?
I would like to know what header column is being pressed, because I have some labels in the tableview and Servoy doesn’t sort on these columns. So I need to find out what columnheader is pressed and if it is a label, then I have to write coding to do the sort myself.

I guess the tableview is with labelfor functionality otherwise not sure what we could return there. Scripting the label from tableview with labelfor functionality does not work at this moment. There are case(s) for this but I am not sure when this will be implemented.

I’ve tested both with LabelFor and without.
Also the columnheader without LabelFor doesn’t return an elementname

What element name should it return when using the default table header ?

Hi Martin,

Servoy passes arguments to the method being called. Arguments[0] contains the name of the dataprovider.
We use the header of the first column sometimes to call the ‘add record method’. For that reason we have attached this columns dataprovider to a global variable called: ‘btnNew’.

Then we use the following code:

function onSort()
{
	var Arg1	= arguments[0] // name
	var Arg2 	= arguments[1] // true
	var $form	= arguments[2];

	if(Arg1 == 'globals.btnNew')
	{
		// do the action...
	}
	
	else
	{
		if(Arg2 == true)
		{
			forms[$form].controller.sort(Arg1 + ' desc');
		}
		else
		{
			forms[$form].controller.sort(Arg1 + ' asc');
		}
	}
}

Hope this will help

Hi Marc,

Thanks for your reply. But unfortunately it doesn’t work for me.

When using a standard field without a LabelFor then the result is:

   var Arg1   = arguments[0] // name
   var Arg2    = arguments[1] // true

But when using a field with a LabelFor, then the result is:

   var Arg1   = arguments[0] // null
   var Arg2    = arguments[1] // true

So it looks like what Laurian wrote:

lvostinar:
I guess the tableview is with labelfor functionality otherwise not sure what we could return there. Scripting the label from tableview with labelfor functionality does not work at this moment. There are case(s) for this but I am not sure when this will be implemented.

If it would return the name of the dataprovider element and not the name of the label element, that could also help me, but that doesn’t work either

Martin

This is strange…
we’ve been using customized headers (labels with the ‘labelFor’ property) for a while. I am pretty sure this worked in 3.5.7. so it looks like this has been changed in 3.5.8…

Anyway… in 4.1.0 this works without any problem

The customized headers are working.
The problem is that onSort Servoy doesn’t tell me what header was pressed.

If you are sure it worked in 3.5.7, check if it still works in your application in 3.5.8
If not, then this is a bug
I’m not able the upgrade to 4.x yet