FEATURE: controller.sortStatus property

After a bit of digging I haven’t found a way to determine if Servoy is tracking the sort status. It would be nice to have Servoy know the sort state and what fields it was last sorted on and in which direction. I envision the following method to emulate the toggle sorting in most modern OS columns.

if (controller.sortStatus == ‘myfield asc’){
controller.sort(‘myfield desc’)}
else{
controller.sort(‘myfield asc’)
)

If this is doable today then please advise. It would seem wasteful to have to create a global to track this when this could be either a global or form specific property that can be checked aginst.

I’m trying to find an answer to this too. Is there a property or function that we can use to determine the current sort order and direction?

What is the reason you would want this?

Hi Marcel, good question.

When we have a header on a tableview, we lose the nice feature of clicking on the header to sort. First click sorts ASC, second DESC.

To simulate this, I have a method to sort the records. I’m wondering if I can avoid using globals to store the last field clicked and whether it’s been clicked once or twice.

Hmm, ok I understand now.

In that case I can imagine it could be of help. My learning point of today :)

Is it that you don’t want to use globals or that you don’t want a cluttered list of globals in your globals tree/dataprovider editor?

If it is the last, you can use globals without declaring them first! So just using globals.sortorder = true/false would work…

IT2Be:
Is it that you don’t want to use globals or that you don’t want a cluttered list of globals in your globals tree/dataprovider editor?

A little from A and a little from B ;-)

If it is the last, you can use globals without declaring them first! So just using globals.sortorder = true/false would work…

I didn’t know you could do that! This is my learning point of today!

Glad I have been of help to add a little to your knowledge :)

Downside of it is that you can not attach the global to a field anymore…

antonio:
When we have a header on a tableview, we lose the nice feature of clicking on the header to sort. First click sorts ASC, second DESC.

Tip: use a Title Header instead and you won’t loose the sorting capability. ;)

You can also use a header and have your own buttons and stuff - and not have to have an individual global for each sort state. You can, instead have a single global (MEDIA type) and store an array of the sort states of each field.

Then have a master routine to loop through the array (VERY fast!) and build your sort statement.

You can, instead have a single global (MEDIA type) and store an array of the sort states of each field. 

I use this technique for almost everything that doesn’t have to survive a session. It is fast, requires only two methods (or even on), one to store a setting and one to retrieve and doesn’t produce traffic on the database. If you know what you are doing, you don’t even have to create that global as a dataprovider (since you never want to use it in a form). That was an excellent tip by Bob!

I continue to be pleasantly surprised by how much easier it is to do things in Servoy!

Is there an implementation of the array approach in one of the example apps?

I too could use a little more elaboration on Bob’s tip. I don’t completely understand.

Hello Guys,

Just to let you get a different appoach:

I use the Tooltip function of the header element to store the sort order and the user can now also get the information on which colomn and in what order his list is sorted, including text colors or sort symbols

The sort method

if (elements.Header_Assigned_To.toolTipText == 'Descending' || elements.Header_Assigned_To.toolTipText == null)
	{
		Sort_Reset_Sort_Headers()
		controller.sort('assigned_to asc')
		elements.Header_Assigned_To.fgcolor = '#006600'
		elements.Header_Assigned_To.toolTipText = 'Ascending'
	}
else
	{
		Sort_Reset_Sort_Headers()
		controller.sort('assigned_to desc')
		elements.Header_Assigned_To.fgcolor = '#0000ff'
		elements.Header_Assigned_To.toolTipText = 'Descending'
	}

A submethod to reset all other column headers (Sort_Reset_Sort_Headers() in the above method)

elements.Header_Assigned_To.fgcolor = '#000000'
elements.Header_Category.fgcolor = '#000000'
elements.Header_Call_Description.fgcolor = '#000000'
elements.Header_Counter.fgcolor = '#000000'

elements.Header_Assigned_To.toolTipText = null
elements.Header_Category.toolTipText = null
elements.Header_Call_Description.toolTipText = null
elements.Header_Counter.toolTipText = null

you can make this a global method and loop though the elements using the “forms[formname].elements.allnames”.

The only disadvantage of using this globally is when you have to sort multiple columns in one columnheader.

Kind Regards Rene