Reference
Index
kDataGrid() - Creates a kDataGrid instance.
set_db_type() - Sets the database wrapper.
set_db_params() - Sets database connectivity parameters.
map_table() - Maps a database table.
map_query() - Maps a custom query.
set_columns_readonly() - Sets one or more columns to read-only.
set_columns_hidden() - Prevents one or more columns from being displayed.
set_column_headers() - Renames one or more columns.
set_column_formats() - Formats one or more columns.
set_columns_maxlength() - Truncates one or more columns.
set_columns_width() - Sets the width of specific grid columns.
show_actions() - Specifies which actions should be displayed.
block_actions() - Blocks specific actions from displayed.
set_theme() - Sets the active theme.
set_edit_in_place() - Enables or disables edit-in-place.
set_pagination() - Enables or disables pagination.
set_items_per_page() - Sets the number of rows per page.
set_css_id() - Sets the grid CSS id.
set_arg() - Sets custom $_GET arguments that should be appenden for every generated link.
set_confirm_delete() - Sets whether a confimation dialog should be shown before deleting an item from the grid.
set_cache() - Enables/disables caching.
set_cache_clean_actions() - Sets which actions should trigger a cache clean-up.
Methods
kDatagrid::kDataGrid()- Creates a kDataGrid instance.
Definition:
kDatagrid kDatagrid::kDataGrid();
Example:
<?php
include('kdatagrid.php');
$grid = new kDataGrid();
//Show the grid
$grid->show();
?>
kDatagrid::set_db_type() - Sets the database wrapper.
Version 1.2+
Definition:
void kDatagrid::set_db_type(string db_type);
Example:
<?php
include('kdatagrid.php');
$grid = new kDataGrid();
//Set the database wrapper for Postgres
$grid->set_db_type('pgsql');
$grid->set_db_params('localhost', 'root', 'password', 'db');
$grid->map_query('clients', 'SELECT * from `clients`');
//Show the grid
$grid->show();
?>
Notes:
- Accepted values are: mysql for MySql, pgsql for Postgres, oracle for Oracle, mssql for SQL Server 2005.
- If no value is given, MySql is used by default.
- For Version 1.2 only, this method must be called before set_db_params().
kDatagrid::set_db_params() - Sets database connectivity parameters.
Definition:
void kDatagrid::set_db_params(string host, strin username, string password, string database [, bool persistent]);
Example:
<?php
include('kdatagrid.php');
$grid = new kDataGrid();
$grid->set_db_params('localhost', 'root', 'password', 'db');
$grid->map_table('clients');
//Show the grid
$grid->show();
?>
Notes:
- Parameter persistent was introducted in version 1.3
- Parameter persistent specifies whether a persistent connection should be used or not. Defaults to false.
kDatagrid::map_table() - Maps a database table.
Definition:
void kDatagrid::map_table(string table_name);
Example:
<?php
include('kdatagrid.php');
$grid = new kDataGrid();
$grid->set_db_params('localhost', 'root', 'password', 'db');
$grid->map_table('clients');
//Show the grid
$grid->show();
?>
kDatagrid::map_query() - Maps a custom query.
Definition:
void kDatagrid::map_query(string table_name, string query);
Example:
<?php
include('kdatagrid.php');
$grid = new kDataGrid();
$grid->set_db_params('localhost', 'root', 'password', 'db');
$grid->map_query('clients', 'SELECT * from `clients`');
//Show the grid
$grid->show();
?>
kDatagrid::set_columns_readonly() - Sets one or more columns to read-only.
Definition:
void kDatagrid::set_columns_readonly(array columns);
void kDatagrid::set_columns_readonly(string column1 [, string column2 [, string ...]]);
Example:
<?php
include('kdatagrid.php');
$grid = new kDataGrid();
$grid->set_db_params('localhost', 'root', 'password', 'db');
$grid->map_query('clients', 'SELECT * from `clients`');
//set the Country and Phone columns to read-only i.e. no edit-in-place
$grid->set_columns_readonly('Country', 'Phone');
//Show the grid
$grid->show();
?>
kDatagrid::set_columns_hidden() - Prevents one or more columns from being displayed.
Definition:
void kDatagrid::set_columns_hidden(array columns);
void kDatagrid::set_columns_hidden(string column1 [, string column2 [, string ...]]);
Example:
<?php
include('kdatagrid.php');
$grid = new kDataGrid();
$grid->set_db_params('localhost', 'root', 'password', 'db');
$grid->map_query('clients', 'SELECT * from `clients`');
//Hides the Country and Phone columns from display
$grid->set_columns_hidden('Country', 'Phone');
//Show the grid
$grid->show();
?>
kDatagrid::set_column_headers() - Renames one or more columns.
Definition:
void kDatagrid::set_column_headers(array headers);
Example:
<?php
include('kdatagrid.php');
$grid = new kDataGrid();
$grid->set_db_params('localhost', 'root', 'password', 'db');
$grid->map_query('clients', 'SELECT * from `clients`');
//renames the 'Zip' column to 'Postal code'
$grid->set_column_headers(array('Zip' => 'Postal code'));
//Show the grid
$grid->show();
?>
kDatagrid::set_column_formats() - Formats one or more columns.
Definition:
void kDatagrid::set_column_formats(array formats);
Example:
<?php
include('kdatagrid.php');
$grid = new kDataGrid();
$grid->set_db_params('localhost', 'root', 'password', 'db');
$grid->map_query('clients', 'SELECT * from `clients`');
//Format the e-mail column to display a mailto link
$grid->set_column_formats(array('Email' => '<a href="mailto:%1$s">%1$s</a>'));
//Show the grid
$grid->show();
?>
kDatagrid::set_columns_maxlength() - Truncates one or more columns.
Definition:
void kDatagrid::set_columns_maxlength(array lengths);
Example:
<?php
include('kdatagrid.php');
$grid = new kDataGrid();
$grid->set_db_params('localhost', 'root', 'password', 'db');
$grid->map_query('clients', 'SELECT * from `clients`');
//Sets the 'Email' and 'Address' columns to display a maximum of 10 characters
$grid->set_columns_maxlength(array('Email' => 10, 'Address' => 10));
//Show the grid
$grid->show();
?>
kDatagrid::set_columns_width() - Truncates one or more columns.
Version 1.2+
Definition:
void kDatagrid::set_columns_width(array widths);
Example:
<?php
include('kdatagrid.php');
$grid = new kDataGrid();
$grid->set_db_params('localhost', 'root', 'password', 'db');
$grid->map_query('clients', 'SELECT * from `clients`');
//Sets the 'Email' and 'Address' columns to display a maximum of 10 characters
$grid->set_columns_width(array('Email' => '100px', 'Address' => '200px'));
//Show the grid
$grid->show();
?>
kDatagrid::show_actions() - Specifies which actions should be displayed.
Definition:
void kDatagrid::show_actions(array actions);
void kDatagrid::show_actions(string action1 [, string action2 [, string action3 [, string action4]]]);
Example:
<?php
include('kdatagrid.php');
$grid = new kDataGrid();
$grid->set_db_params('localhost', 'root', 'password', 'db');
$grid->map_query('clients', 'SELECT * from `clients`');
//Only show View and Add actions
$grid->show_actions('add', 'view');
//Show the grid
$grid->show();
?>
kDatagrid::block_actions() - Blocks specific actions from displayed.
Version 1.2+
Definition:
void kDatagrid::block_actions(array actions);
void kDatagrid::block_actions(string action1 [, string action2 [, string action3 [, string action4]]]);
Example:
<?php
include('kdatagrid.php');
$grid = new kDataGrid();
$grid->set_db_params('localhost', 'root', 'password', 'db');
$grid->map_query('clients', 'SELECT * from `clients`');
//Block Edit abd Delete actions
$grid->block_actions('edit', 'delete');
//Show the grid
$grid->show();
?>
kDatagrid::set_theme() - Sets the active theme.
Definition:
void kDatagrid::set_theme(string theme);
Example:
<?php
include('kdatagrid.php');
$grid = new kDataGrid();
$grid->set_db_params('localhost', 'root', 'password', 'db');
$grid->map_query('clients', 'SELECT * from `clients`');
//Set 'Luna' as the active theme
$grid->set_theme('luna');
//Show the grid
$grid->show();
?>
kDatagrid::set_edit_in_place() - Enables or disables edit-in-place.
Definition:
void kDatagrid::set_edit_in_place(bool value);
Example:
<?php
include('kdatagrid.php');
$grid = new kDataGrid();
$grid->set_db_params('localhost', 'root', 'password', 'db');
$grid->map_query('clients', 'SELECT * from `clients`');
//Disable edit-in-place functionality
$grid->set_edit_in_place(false);
//Show the grid
$grid->show();
?>
kDatagrid::set_pagination() - Enables or disables pagination.
Definition:
void kDatagrid::set_pagination(bool value);
Example:
<?php
include('kdatagrid.php');
$grid = new kDataGrid();
$grid->set_db_params('localhost', 'root', 'password', 'db');
$grid->map_query('clients', 'SELECT * from `clients`');
//Disable pagination
$grid->set_pagination(false);
//Show the grid
$grid->show();
?>
kDatagrid::set_items_per_page() - Sets the number of rows per page.
Definition:
void kDatagrid::set_items_per_page(int value);
Example:
<?php
include('kdatagrid.php');
$grid = new kDataGrid();
$grid->set_db_params('localhost', 'root', 'password', 'db');
$grid->map_query('clients', 'SELECT * from `clients`');
//Set the number of rows per page to 20
$grid->set_items_per_page(20);
//Show the grid
$grid->show();
?>
kDatagrid::set_css_class() - Sets the grid CSS class.
Version 1.2+
Definition:
void kDatagrid::set_css_class(string css_class);
Example:
<?php
include('kdatagrid.php');
$grid = new kDataGrid();
$grid->set_db_params('localhost', 'root', 'password', 'db');
$grid->map_query('clients', 'SELECT * from `clients`');
//Set the CSS class to grid
$grid->set_css_class('grid');
//Show the grid
$grid->show();
?>
kDatagrid::set_css_id() - Sets the grid CSS id.
Version 1.2+
Definition:
void kDatagrid::set_css_id(string css_id);
Example:
<?php
include('kdatagrid.php');
$grid = new kDataGrid();
$grid->set_db_params('localhost', 'root', 'password', 'db');
$grid->map_query('clients', 'SELECT * from `clients`');
//Set the CSS id to myDataGrid
$grid->set_css_id('myDataGrid');
//Show the grid
$grid->show();
?>
kDatagrid::set_arg() - Sets custom $_GET arguments that should be appenden for every generated link.
Version 1.3+
Definition:
void kDatagrid::set_arg(string key, string value);
void kDatagrid::set_arg(array args);
Example:
<?php
include('kdatagrid.php');
$grid = new kDataGrid();
$grid->set_db_params('localhost', 'root', 'password', 'db');
$grid->map_query('clients', 'SELECT * from `clients`');
//Create a variable called 'key' with value of 'value' ( $_GET['key'] = 'value' )
$grid->set_arg('key', 'value');
//Show the grid
$grid->show();
?>
kDatagrid::set_confirm_delete() - Sets whether a confimation dialog should be shown before deleting an item from the grid.
Version 1.3+
Definition:
void kDatagrid::set_confirm_delete(bool value);
Example:
<?php
include('kdatagrid.php');
$grid = new kDataGrid();
$grid->set_db_params('localhost', 'root', 'password', 'db');
$grid->map_query('clients', 'SELECT * from `clients`');
//Disable confirmation
$grid->set_confirm_delete(false);
//Show the grid
$grid->show();
?>
kDatagrid::set_cache() - Enables/disables caching.
Version 1.3+
Definition:
void kDatagrid::set_cache(bool enable [, int maximum_age [, string salt]]);
Example:
<?php
include('kdatagrid.php');
$grid = new kDataGrid();
$grid->set_db_params('localhost', 'root', 'password', 'db');
$grid->map_query('clients', 'SELECT * from `clients`');
//Enable caching.
$grid->set_cache(true);
//Show the grid
$grid->show();
?>
Notes
- Maximum cache age is 900 seconds by default.
kDatagrid::set_cache_clean_actions() - Sets which actions should trigger a cache clean-up.
Version 1.3+
Definition:
void kDatagrid::set_cache_clean_actions(array actions);
void kDatagrid::set_cache_clean_actions(string action1 [, string action2 [, string ...]]);
Example:
<?php
include('kdatagrid.php');
$grid = new kDataGrid();
$grid->set_db_params('localhost', 'root', 'password', 'db');
$grid->map_query('clients', 'SELECT * from `clients`');
//Enable caching.
$grid->set_cache(true);
//Specify that only adding and editing should clean the cache.
$grid->set_cache_clean_actions('add', 'edit');
//Show the grid
$grid->show();
?>
Notes
- By default all actions will perform a cache clan-up if successful.

