Demo
Launch demo
The demo shows a default kDataGrid installation mapping a MySql table storing client information. Opens in a new window.
The demo explained
<?php
//include the kDataGrid library
include('kdatagrid.php');
//create a new grid
$grid = new kDataGrid();
//set database connectivity parameters
$grid->set_db_params('localhost', 'username', 'password', 'database');
//map the clients table
$grid->map_table('clients');
//hide some columns
$grid->columns_hidden = array('Created', 'Modified', 'Type', 'Address');
//make some columns readonly
$grid->set_columns_readonly('Country', 'Phone');
//sort by Name columns as default
$grid->sort_by = 'Name';
//specify a custom header for the Zip column
$grid->set_column_headers(array('Zip' => 'Postal code'));
//format the Email column to display a mailto link and a maximum of 10 characters
$grid->set_column_formats(array('Email' => '<a href="mailto:%1$s">%.10s...</a>'));
//limit the Address column to 10 characters
$grid->set_columns_maxlength(array('Address' => 10));
//set the available actions
$grid->show_actions('view', 'edit', 'add');
//show the grid
$grid->show();
?>

