Datagrid for PHP

In this post I will share a PHP program source to create Datagrid. Well everyone of you must know that Datagrid sometimes play important role to display the data that we query from our database.

In this post I will share how to integrate the datagrid application given below to your webpage. I will only give the basic feature how to use it, just to display data, since this is all we most need. You can read the full documentation in the readme inside the file.

If we put it simply, this datagrid application only need a query as a data source that you must set and after that you just need to adjust some settings to your datagrid and finally you just need to bind the datagrid to display your data.

I will guide you step by step to use this application(note that you can always refer to the documentation of the file inside). To use the datagrid, you must put :

define ("DATAGRID_DIR", "../datagrid/"); -> Your path to the datagrid folder
define ("PEAR_DIR", "../datagrid/pear/");

Next we must include the file needed as library and source for our function :

require_once(DATAGRID_DIR.'datagrid.class.php');
require_once(PEAR_DIR.'PEAR.php');
require_once(PEAR_DIR.'DB.php');

Next we must configure the data to connect and use a database :

$DB_USER='root';
$DB_PASS='';
$DB_HOST='localhost';
$DB_NAME='apkomindo_site';

For MySQL user you need to attach this code to make connection and start the datagrid processing :

ob_start();
$db_conn = DB::factory('mysql');
$db_conn -> connect(DB::parseDSN('mysql://'.$DB_USER.':'.$DB_PASS.'@'.$DB_HOST.'/'.$DB_NAME));
Set some of the properties needed for the Datagrid(default) :

$debug_mode = false;
$messaging = true;
$unique_prefix = "f_";
$dgrid = new DataGrid($debug_mode, $messaging, $unique_prefix, DATAGRID_DIR);

Next we must define the data source using SQL Query :

$sql = $query;
$dgrid->dataSource($db_conn, $sql, $default_order_field, $default_order_type);
Next we only need to set some options for our datagrid :

$dgrid->setAutoColumnsInViewMode(true);
$sorting_option = true;
$dgrid->allowSorting($sorting_option);
$paging_option = true;
$rows_numeration = false;
$numeration_sign = "N #";
$dgrid->allowPaging($paging_option, $rows_numeration, $numeration_sign);
$bottom_paging = array("results"=>true, "results_align"=>"left", "pages"=>true, "pages_align"=>"center", "page_size"=>true, "page_size_align"=>"right");
$top_paging = array();
$pages_array = array("10"=>"10", "25"=>"25", "50"=>"50", "100"=>"100", "250"=>"250", "500"=>"500", "1000"=>"1000");
$default_page_size = 10;
$dgrid->setPagingSettings($bottom_paging, $top_paging, $pages_array, $default_page_size);
$dgrid->SetEditModeTableProperties(false);
$dgrid->SetDetailsModeTableProperties(false);
$dgrid->SetColumnsInEditMode(false);
$dgrid->SetAutoColumnsInEditMode(false);
$dgrid->AllowMultirowOperations(false);
$dgrid->AllowPrinting(false);
$dgrid->SetModes(false);

Finally we just need to bind our datagrid and do some cleaning :

$dgrid->bind();
ob_end_flush();

If we attach the code above, your datagrid will disable the view, edit, and delete mode. To customize the datagrid base on your needs you must read the documentation given inside the file. This datagrid for PHP is an easy to use application to be integrated with our application. This datagrid also supports filtering feature, edit, view, and delete mode.

If you want to download the datagrid files you can find it in :
http://www.4shared.com/file/228119911/61204e4b/PHP_Datagrid.html

You can extract it and don't forget, to use it, you need to set the path to your datagrid directory according to your folder name.

Also, don't forget to give credits to the developer. Well I hope this application helps you a lot in your application development.

Tags : php datagrid, datagrid for php, php datagrid tutorial, using datagrid php, php tutorial.

Best Regards,
Admin

0 comments: