Dynamic search

What is the best way to implement dynamic search with a type-ahead list that updates from the database as the user is typing?

Hi Maria,

Have you tried connecting the field to a valuelist.
The contents of the type-ahead will be dictated by the value list.
W/o a value list, it will just query the entire database on that column, minus anything filtered out by foundset/table filter params.

Hope this helps,
Sean

Hi Sean,

Thanks for your suggestion.

Yes, I connected the the field to a valuelist but the valuelist is generated programmatically (because we want the values to come from more than one column and even more than one table, say, from both ‘firstname’ and ‘lastname’ - that’s one table - and ‘employeecode’ - that’s another table). As long as the valuelist is based on different columns I set the dataprovider for the field to a local variable.
To load the valuelist with relevant values I do three queries, one for firstname, one for lastname, one for employeecode. Then I concatenate the three resulting arrays and load them into one valuelist.

This solution looks a bit awkward but it works so far. Another problem with it is that I would like to limit the number of values in the type-ahead list to 10 and eliminate the vertical scroll-bar (do we have control over that?). This will make me have to refresh the valuelist each time the user types anything in the field. I suppose we don’t have the control over this level field events in Servoy, do we? Is there a way to set a kind of a timer that will refresh the valuelist?

Thanks a lot.
Maria

Hi,

maria:
This solution looks a bit awkward but it works so far. Another problem with it is that I would like to limit the number of values in the type-ahead list to 10 and eliminate the vertical scroll-bar (do we have control over that?). This will make me have to refresh the valuelist each time the user types anything in the field. I suppose we don’t have the control over this level field events in Servoy, do we? Is there a way to set a kind of a timer that will refresh the valuelist?

The initial list you obtain from the table(s) can be limited by setting the ‘max_returned_rows’ argument to 10 on the ‘databaseManager.getDataSetByQuery(server_name,sql_query,arguments,max_returned_rows)’ function. But to maintain that value list item count as the user narrows down his field value is not possible, I don’t think, as there is no key stroke event for a text field nor a timer to refresh it after x no of milliseconds. Although I believe there is going to be a facility to set an on key stroke event for a field, on the next version release of Servoy 4.1.3 I believe, so you can use that to refresh your value list and maintain a value list count of 10 as the user narrows down on the fieldvalue. Maybe someone from Servoy can confirm this.
Hope this helps.

Good Luck