Skip to content

Experimental

This requires additional severver side programming. Do not use in production.

Version

Since 2022/12

Custom Lookup (Serverside)

AppGini Helper Javascript Library is a pure clientside extension, which runs in the browser. Whenever we need data from the server, this can not be done by just using clientside code, but we need additional serverside code which serves data from the server to the client, requested by the client. You can use a custom PHP script, returning JSON in a specific format or order our services for programming such.

(1) Prerequisites

  1. Requires a normal <input/> field in your model and database
  2. Requires a serverside script which can read the request parameters.

    This serverside script is NOT part of AppGiniHelper Javascript Library

(2) Client Side Code

1
2
3
4
5
// file: hooks/TABLENAME-dv.js
var dv = AppGiniHelper.dv;
var f = dv.getField("COLUMNNAME");
var url = "your_script_for_getting_lookup_entries.php";
f.toServerLookup("api.php?q=/employees/lookup");

(3) Server Side code

Request

Client sends a request having as parameter named search . This contains the user input inside the search-field of the dropdown control.

1
2
3
4
5
<?php 

$search_term = $_REQUEST['search'];

// build your SQL query, fetch data from database, return to the client

Your script has to return an JSON-encoded array like the following:

1
2
3
4
5
6
7
8
9
[
    'success' => true,
    'data' => [
        ['id'=>1, 'text'=>'Item A'],
        ['id'=>10, 'text'=>'Item B'],
        ['id'=>17, 'text'=>'Item C']

    ]
];

See also