AmbiGrid Sample4

It demonstrates AmbiGrid data editing capabilities.

Run Sample4

Sample source code:

<?php
require_once '../grid/main.php';

// getting SimpleAPI class
$api XC_AmbiGrid::getSimpleAPI();
// defining db provider parameters $select_query = <<<ENDOFQUERY SELECT Code, Name, Continent, Region, SurfaceArea, Population, GovernmentForm, HeadOfState FROM Country ENDOFQUERY;
$insert_query = <<<ENDOFQUERY INSERT INTO Country   (Code, Name, Continent, Region, SurfaceArea, Population, GovernmentForm, HeadOfState)   VALUES (@0, @1, @2, @3, @4, @5, @6, @7) ENDOFQUERY;
$update_query = <<<ENDOFQUERY UPDATE Country SET   Code = {@Code},   Name = {@Name},   Continent = {@Continent},   Region = {@Region},   SurfaceArea = {@SurfaceArea},   Population = {@Population},   GovernmentForm = {@GovernmentForm},   HeadOfState = {@HeadOfState} WHERE Code = {@@Code} ENDOFQUERY;
$delete_query = <<<ENDOFQUERY DELETE FROM Country WHERE Code = @@Code ENDOFQUERY;
$params = array(     'db_type'     => 'MySql',     'db_name'     => 'xcodeco_world',     'db_server'   => 'localhost',     'db_username' => 'username',     'db_password' => 'password',     'cmd_select'  => $select_query,     'cmd_insert'  => $insert_query,     'cmd_update'  => $update_query,     'cmd_delete'  => $delete_query );
// creating provider and grid $provider $api->createProvider($params); $grid $api->createGrid('xcDataGrid1'$provider25);
// 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(); ?> <link rel="stylesheet" type="text/css" href="silver.css" /> </head>
<body> <div id="xcDataGrid1" style="width: 1200px;">     <table>     <thead>         <tr>             <td>Code</td>             <td>Name</td>             <td>Continent</td>             <td>Region</td>             <td>Surface Area</td>             <td>Population</td>             <td>Government Form</td>             <td>Head of State</td>         </tr>     </thead>     <tbody>         <tr>             <td>{Code}</td>             <td>{Name}</td>             <td>{Continent}</td>             <td>{Region}</td>             <td>{SurfaceArea} km<sup>2</sup></td>             <td>{Population}</td>             <td>{GovernmentForm}</td>             <td>{HeadOfState}</td>         </tr>     </tbody>     <tfoot>     </tfoot>     </table> </div> </body> </html>

Comments:

- Current version of AmbiGrid has basic data manipulation capabilities, including adding rows, deleting rows and editing existing rows. AmbiGrid provides two data editing modes:

1. Single row mode when changes to the row made on the client are immediately sent to the server.

2. Batch mode when changes are accumulated on the client and are sent to the server altogether on commit operation (usually it is pressing "Commit Changes" button).

- In order to enable data editing you need to specify tree additional SQL statements for adding, editing and deleting database records. If some of those statements are not defined corresponding actions are disabled.

- Note how sql statement parameters are defined. The syntax used is: {@column_name} or {@column_index} where column_index is zero based index of column returned by the SELECT statement.

// getting SimpleAPI class
$api XC_AmbiGrid::getSimpleAPI();

// defining db provider parameters $select_query = <<<ENDOFQUERY SELECT Code, Name, Continent, Region, SurfaceArea, Population, GovernmentForm, HeadOfState FROM Country ENDOFQUERY;
$insert_query = <<<ENDOFQUERY INSERT INTO Country   (Code, Name, Continent, Region, SurfaceArea, Population, GovernmentForm, HeadOfState)   VALUES (@0, @1, @2, @3, @4, @5, @6, @7) ENDOFQUERY;
$update_query = <<<ENDOFQUERY UPDATE Country SET   Code = {@Code},   Name = {@Name},   Continent = {@Continent},   Region = {@Region},   SurfaceArea = {@SurfaceArea},   Population = {@Population},   GovernmentForm = {@GovernmentForm},   HeadOfState = {@HeadOfState} WHERE Code = {@@Code} ENDOFQUERY;
$delete_query = <<<ENDOFQUERY DELETE FROM Country WHERE Code = @@Code ENDOFQUERY;
$params = array(     'db_type'     => 'MySql',     'db_name'     => 'xcodeco_world',     'db_server'   => 'localhost',     'db_username' => 'username',     'db_password' => 'password',     'cmd_select'  => $select_query,     'cmd_insert'  => $insert_query,     'cmd_update'  => $update_query,     'cmd_delete'  => $delete_query );

Back to Samples Content