Hi all,
I use svyLookup and I would like to sort the results using custom PostgreSQL functionality.
ORDER BY CASE WHEN dmetaphone(company_name) = dmetaphone(?) THEN levenshtein(company_name,?) ELSE 0 END,company_name
if the words are similar, I want to order by the levenshtein distance between the words.
Is there any way to use a custom sort like this with svyLookup?
Could you create a view in postgres that you can use as a (inmem) datasource of the lookup? There you should be able to use db-functions?
Hi Christian,
are you using the query builder to apply this custom sort ?
In svyLookup you can provide a custom foundset ( e.g. filtered/sorted ) with this method
// filter product foundset with unitprice > 30
var filteredFS = datasources.db.example_data.products.getFoundSet();
filteredFS.addFoundSetFilterParam("unitprice",">","30","unitprice");
filteredFS.sort("unitprice desc");
filteredFS.loadAllRecords();
// create lookup object with filtered foundset
var lookupObj = scopes.svyLookup.createLookup(filteredFS);
See https://github.com/Servoy/svyLookup/wik … ookup-list
In your use case not sure if will be enough to make sure the custom order is applied while the user is typing ( searching ) in the lookup.
In case is not enough you can look at extending the lookup form and apply your custom sort https://github.com/Servoy/svyLookup/wik … -templates
You need bit of understanding on how the lookup operate and which method to extend ( would be the search method i assume https://github.com/Servoy/svyLookup/blo … up.js#L174 )
Regards,
Paolo
Thanks, both of you.
Extending the lookup form looks promising…