<?php
require_once '../../../fine/elements/grid/FineData.php';
require_once '../../../fine/elements/grid/FineGrid.php';
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "fineuidemo";
$dbcon = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname);
$mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
$pdo = new PDO("mysql:host=$dbhost;dbname=$dbname;charset=utf8", $dbuser, $dbpass);
// set the PDO error mode to exception
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$create = new \Fine\Data\TransportCreate();
$create
->dataType('text')
->method('POST');
$read = new \Fine\Data\TransportRead();
$read
->dataType('text')
->method('POST')
;
$update = new \Fine\Data\TransportUpdate();
$update
->dataType('text')
->method('POST')
;
$destroy = new \Fine\Data\Transportdestroy();
$destroy
->dataType('text')
->method('POST');
$transport = new \Fine\Data\Transport();
$transport
->create($create)
->read($read)
->update($update)
->destroy($destroy);
$customerNumberField = new \Fine\Data\ModelField('customerNumber');
$customerNumberField->type('number')
->editable(true)
->nullable(false)
->defaultValue('');
$customerNameField = new \Fine\Data\ModelField('customerName');
$customerNameField->type('string')
->defaultValue('');
$phoneField = new \Fine\Data\ModelField('phone');
$phoneField->type('number')
->defaultValue('');
$cityField = new \Fine\Data\ModelField('city');
$cityField->type('string')
->defaultValue('');
$countryField = new \Fine\Data\ModelField('country');
$countryField->type('string')
->defaultValue('');
$model = new \Fine\Data\Model();
$model->idField('customerNumber')
->addField($customerNumberField, $customerNameField, $phoneField,
$cityField, $countryField);
$schema = new \Fine\Data\Schema();
$schema->model($model);
$dataSource = new \Fine\Data\DataSource($dbcon);
$dataSource
->pdo($pdo)
->dataTable('customers')
->transport($transport)
->pageSize(20)
->schema($schema)
->serverPaging(true)
->serverFiltering(true)
->serverSorting(true);
$grid = new \Fine\UI\Grid('grid');
$customerNumberColumn = new \Fine\UI\GridColumn();
$customerNumberColumn->field('customerNumber')
->width('75px')
->filtering(false)
->title('ID');
$customerNameColumn = new \Fine\UI\GridColumn();
$customerNameColumn->field('customerName')
->width('35%')
->title('Customer Name');
$phoneColumn = new \Fine\UI\GridColumn();
$phoneColumn->field('phone')
->width('150px')
->filtering(false)
->title('Phone');
$cityColumn = new \Fine\UI\GridColumn();
$cityColumn->field('city')
->title('City');
$countryColumn = new \Fine\UI\GridColumn();
$countryColumn->field('country')
->title('Country');
$commandColumn = new \Fine\UI\GridColumn();
$commandColumn->commands(array('Edit', 'Delete'))
->editCommands(array("Save", "Cancel"))
->filtering(false)
->width('170px');
$grid->addColumn($customerNumberColumn, $customerNameColumn, $phoneColumn,
$cityColumn, $countryColumn, $commandColumn)
->dataSource($dataSource)
->showToolbar(true)
->height('400px')
->paging(true)
->filtering(true)
->sorting(true);
$grid->process();
echo $grid->render();
?>