pbakker:
This is 3.5 right?
Doesn’t the onsort Cmd method get passed soem arguments on which you can figure out which column (or related dataprovider) is clicked?
That’s true Paul, thanks!
We’re talking about Servoy 3.5 here, indeed.
The onSortCmd returns in Servoy 3.5 the fieldname that you’ve clicked on AND and the sort order!
For example:
//onSortCmd method
var vFieldName = arguments[0]
var vSort = arguments[1]
plugins.dialogs.showInfoDialog( 'Info', 'Sorted by ' + vFieldName + '.', 'OK')
vSort returns true or false. I guess that stands for ascending or descending.
Very cool!
We like to sort a column in a table-view based on another column!
example:
We have a calculation that translates todays date to: Today
the date of yesterday, to: Yesterday, etc…etc…
but if someone clicks the column we don’t want to sort on that text, but on the REAL date column.
pbakker:
Karel, it works fine for me, I think the problem is in your method: Why are you placing vEsc in front and behind the sort criteria?
You’re right, Paul, thanks. The vEsc doesn’t need to be in there. Without the quotes the method runs perfectly
So this is the way to run a custom onSortCmd Method inServoy 3.5:
//get form-, field and sort values
var vForm = application.getMethodTriggerFormName()
var vFieldName = arguments[0]
var vSort = arguments[1]
//convert sort boolean to string
var vSortString = 'asc'
if(vSort == false) {
var vSortString = 'desc'
}
//set your customized field name
if(vFieldName == 'name_display') {
vFieldName = 'name_last'
}
var vString = vFieldName + " " + vSortString
//sort the foundset
forms[vForm].controller.sort(vString)
pbakker:
BTW, did you notice that it’s now also possible to apply a scripted sort when a column header of an unstored calculation is clicked?
Even the click on a tableheader of a column displaying an unstored calculation is ported via the onSortCmd command.
Paul
Very cool! I also think it’s a great option to PREVENT a user from sorting a column.
Only missing thing (concerning my tableview wishlist ) is being able to store/restore the colomn location in tableview. That way we could save the location of the field when the user dragges a fieldrow to another location.