It demonstrates basic AmbiGrid functionality.
Sample source code:
<?php
require_once 'grid/main.php';
// getting SimpleAPI class
$api = XC_AmbiGrid::getSimpleAPI();
// defining db provider parameters
$params = array(
'db_type' => 'MySql',
'db_name' => 'your_db_name',
'db_server' => 'localhost',
'db_username' => 'username',
'db_password' => 'password',
'cmd_select' => "SELECT * FROM Country"
);
// creating provider and grid
$provider = $api->createProvider($params);
$grid = $api->createGrid('xcDataGrid1', $provider, 25);
// after all initialization call to processAjaxRequest() required
$api->processAjaxRequest();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>SimpleAPI example</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php $api->printJS(); ?>
</head>
<body>
<div id="xcDataGrid1"></div>
</body>
</html>
Comments:
- Firstly we need to include main.php file from AmbiGrid installation folder. Make sure the path is correct:
require_once 'grid/main.php';
- Then we need to get reference to SimpleAPI class. In general API classes are interface between page and AmbiGrid core and main developer instrument. Currently only one such class available - SimpleAPI.
$api = XC_AmbiGrid::getSimpleAPI();
- Then we defining database provider parameters: db type (currently only MySQL supported), db name, server, username, password and select statement. Data returned by select statement will be displayed in AmbiGrid:
$params = array(
'db_type' => 'MySql',
'db_name' => 'your_db_name',
'db_server' => 'localhost',
'db_username' => 'username',
'db_password' => 'password',
'cmd_select' => "SELECT * FROM Country"
);
- Next we create provider object by createProvider() API call. Provider suplies AmbiGrid with data:
$provider = $api->createProvider($params);
- Then we create grid object by createGrid() API call. It takes three parameters: first is ID of HTML placeholder element (usually DIV) to which AmbiGrid will be rendered, second parameter is provider object, third is number of lines per page:
$grid = $api->createGrid('xcDataGrid1', $provider, 25);
- After all initialization we need to call processAjaxRequest() API method. As you can guess it responds to subsequent ajax requests from AmbiGrid:
$api->processAjaxRequest();
- Next attention point is printJS() call inside of HTML head section. It renders necessary javascripts to the page:
<head>
<title>SimpleAPI example</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<?php $api->printJS(); ?>
</head>
- At last we need to insert placeholder for our AmbiGrid. Usually this is DIV tag which ID is passed as first parameter to createGrid() call:
<div id="xcDataGrid1"></div>