Have some issues with loading records via query and then printing/previewing:
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(), vQuery,null, maxReturnedRows)
controller.loadRecords(dataset)
The query correctly sets the order (via ORDER BY) but Servoy doesn’t aware of this order.
Printing, print preview, and getcurrentsort functions do not honor the order passed.
Setting the sort AFTER loading re-queries the db:
controller.sort("column_name DESC")
Is there any way to pass the sort order to Servoy WITHOUT querying the database twice (once to get PK’s, another to sort) so that printing and preview works as intended?
Or to force Servoy to maintain the current sort when previewing and printing?
Thanks for any info.
I’ve seen other reports of this:
With no replies.
Does no one use a query that loads a form and then need to print from it in the same order as what is displayed?
The print and printpreview set the order according the default form sort (or by pk if none is set)
The problem is, Servoy will ALWAYS sort by the default form sort even if a different order is displayed onscreen via the ORDER BY in the SQL. getcurrentsort returns the default, regardless of what it really is onscreen so printpreview fetches the default.
Granted, I know that servoy sorts must be column_based, and I’ve tried created the necessary columns.
Even then, servoy doesn’t know about the sort order given by a loadrecords(query) or a loadrecords(datasetbyquery) and so the print and preview is always different that what is shown on the screen (unless of course it exactly matches the forms default sort!).
The only way around it is to explicitly load the records, then RE-load via a controller.sort with the column you want sorted on.
Then, its re-loading AGAIN to form the printpreview.
This can lead to 5-10 sec just to print out a list of about 10-25 records.
If there was a way to set the sort order explicitly WITHOUT actually sorting…so that any further actions (like printing or preview) know what the sort order is.
a method like:
.setSort()
``` in the foundset class.
OR
Parse the query handed to loadRecords or getdatasetasquery and pass the ORDER BY to Servoy.
OR
Add an argument to both of the above to explicity form the ORDER BY clause and subsequently inform Servoy of such.
controller.loadRecords( [foundset/pkdataset/query], [queryArgumentsArray],[ORDER BY array])
databaseManager.getDataSetByQuery(servername, sql_query, Object[] arguments, number maxReturnedRows,[ORDER BY array])
NCM
FSCI
More than that, what displays on the screen should be what prints - and having to explicitly sort every foundset just to keep the display and the printpreview the same doesn’t follow expected behavior.
What if the ORDER BY in the SQL is not column based? Like ORDER BY sumofsales - sumofinv ?
Servoy will display this in the correct order, BUT provides no way to print in that same order (unless you have a stored calc field AND methods to capture ALL times when inventory and sales might change and update the parent record as Servoy will not do this automatically if the parent record is not displayed somewhere first).
Its just not behavior that I expected, and don’t think anyone would - that a foundset displayed on the screen will not print in the same order.
Also, if you manually SORT (or sort via method) and then happen to load a different foundset via query Servoy still thinks the sort is the same as what it was last sorted on. It doesn’t reset, it doesn’t revert to the form default, it just maintains the last sortstring even though that doesn’t match the order of the foundset. Then, on printing / previewing, of course the records will be sorted by the sortstring in servoy’s memory, not by any default or currently displayed order.
This is not expected behavior.
Granted, this will only affect those who are using different ORDER BYs based on criteria set by the user in an SQL statement, but looking through this forum, this exact scenario is advised many times - with no caveat that:
display sort order from SQL != (servoy sortstring) || (print sort order)