PlatinumGrid
develop faster.

PlatinumGrid has an extremely simple and flexible API. This allows developers to begin using PlatinumGrid very quickly, and allows them to access even advanced features with ease. This page demonstrates this easy-to-use API.

PlatinumGrid ships with over 30 examples covering virtually all features of the grid, that provide a simple and effective way of showing how to use the API. We've taken a few of these examples to convey some idea of the simplicity of using PlatinumGrid in any PHP application.

Note. For applications written using RadPHP, PlatinumGrid is a drag-and-drop component with complete integration into the RPCL. This page is intended for the developers who do not use RadPHP.

Persistence:
To persist the grid state during the session is easy. All one has to do is call the grid's serialize and unserialize methods to write/read the grid's state into the session.
<?php
// This demo demonstrates how to store the grid's settings in the session, so that
// sorting, grouping and the other grid settings are preserved between requests.
//
require_once( 'grid.inc.php' );

// Start the session. This tells PHP that we want to use the session, and also
// loads any previously saved data into the $_SESSION global variable.
session_start();

// Connect to the database and load the table.
$dbConnection mysql_connect'localhost''root''' );

mysql_select_db'gridsamples'$dbConnection );

$dataSource = new MySQLDatasource$dbConnection );
$dataSource->DataSet->TableName 'employeestiny';

// Construct the grid, supplying a few default settings.
$grid = new JTPlatinumGrid();
$grid->Datasource $dataSource;
$grid->Height '';
$grid->SiteTheme->Theme 'default';

// This if statement checks if the grid exists in the session and if it does not,
// then it creates the various default settings on the grid. It also allows the session
// state to be reset by supplying restore_session=1 on the query string.
if( !isset( $_SESSION'sid' ] ) || $_GET'restore_session' ] == '1' )
{
    
// The session has not been created, or is being reset, so we set the properties
    // on the grid.
    
$grid->CanRangeSelect false;
    
$grid->Header->ShowFilterBar false;
    
$grid->Height 540;
    
$grid->Width 955;

    
// And create the columns.
    
$textCol1 = new JTPlatinumGridTextColumn$grid );
    
$textCol1->Caption 'First Name';
    
$textCol1->DataField 'FirstName';
    
$textCol1->Name 'FirstNameCol';

    
$textCol2 = new JTPlatinumGridTextColumn$grid );
    
$textCol2->Caption 'Last Name';
    
$textCol2->DataField 'LastName';
    
$textCol2->Name 'LastNameCol';

    
$textCol3 = new JTPlatinumGridTextColumn$grid );
    
$textCol3->Caption 'Department';
    
$textCol3->DataField 'Department';
    
$textCol3->Name 'DepartmentCol';

    
$grid->Columns = array( $textCol1$textCol2$textCol3 );
}
else
{
    
// The session has been created, so we just have to tell the grid to load
    // its state from the session.
    
$grid->unserialize();
}

// Tell the grid to initialize.
$grid->init();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <title>Basic Persistence Demo</title>
<?php
$grid
->dumpHeaderCode();
?>
</head>
<body>
  <h1>Basic Persistence Demo</h1>
  <form action="" method="post">
    <div id="<?php echo( $grid->Name ); ?>_outer">
<?php $grid->dumpContents(); ?>
    </div>
    <input type="submit" value="Click to refresh page" />
  </form>
</body>
</html>
<?php

// Now, we tell the grid to write its state into the session. This will store all
// settings such as sorting, grouping etc.
$grid->serialize();

// Now we store our own variable in the session, so we can tell if the session
// has been created. This variable is used by the if statement above.
$_SESSION'sid' ] = 1;