Skip to content



Steps shows how to integrate database driven type ahead and autocomplete by lookup query.

Basic Typeahead (single field)

Step1: Set formatter to autocomplete on desired column

$col["formatter"] = "autocomplete"; // autocomplete

Step2: Set format options query. The field in sql aliased 'v' will be shown in list

// Fill the name field with query values typeahead
$col["formatoptions"] = array(  "sql"=>"SELECT name as v FROM clients",

Autofill other field.

The field 'company' will be filled w.r.t. selected name.

$col["formatoptions"] = array(  "sql"=>"SELECT company as k, name as v FROM clients",

The field aliased 'k' will be set in the 'updated_field' column (e.g. company)

Callback function

Connect a callback function that will auto-fill multiple fields & search in both name + id,

$col["formatoptions"] = array(  "sql"=>"SELECT *, name as v FROM clients",

and in html part, define callback function.

function fill_form(data)


Force Selection

You can also force to select from one of the options, set force_select => true

// callback function
$col["formatoptions"] = array(  "sql"=>"SELECT *, name as v FROM clients where gender='male' ORDER BY name desc",

By default, autocomplete uses 'contains' search. To switch to 'begins with' set:

$col["formatoptions"]["op"] = "bw";


^ Top