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.

Ajax:
PlatinumGrid fully supports Ajax, and does not tie you into one particular Ajax library, but offers maximum flexibility. To demonstrate this flexibility, this example does not use an Ajax library, but implements the Ajax methods by hand.
<?php
require_once( 'grid.inc.php' );

$dbConnection mysql_connect'localhost''root''' );

mysql_select_db'gridsamples'$dbConnection );

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

// Construct the grid.
$grid = new JTPlatinumGrid();
$grid->ajaxJSMethod 'ajaxCall()';
$grid->Datasource $dataSource;
$grid->Height '';
$grid->SiteTheme->Theme 'default';

$col1 = new JTPlatinumGridTextColumn$grid );
$col1->Caption 'ID';
$col1->DataField 'ID';
$col1->Name 'IDCol';

$col2 = new JTPlatinumGridTextColumn$grid );
$col2->Caption 'First Name';
$col2->DataField 'FirstName';
$col2->Name 'FirstNameCol';

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

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

$grid->Columns = array( $col1$col2$col3$col4 );

$grid->init();

// If it's an Ajax call, handle it.
if( $_POST'ajax' ] == '1' )
{
    
$gridCode $grid->dumpForAjax();

    
$gridResponse = new stdClass();
    
$gridResponse->id $grid->Name '_outerdiv';
    
$gridResponse->html $gridCode];
    
$gridResponse->jsCode $gridCode];

    die( 
json_encode( array( $gridResponse ) ) );
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <title>Basic Ajax Demo</title>
  <script language="JavaScript" type="text/javascript">
// Some boiler-plate Ajax methods. These could easily be handled by an Ajax library
// such as Xajax.
function processAjaxResponse( responseText, callBackParameters ) {
    var elements = eval( responseText );
    for( var i = 0; i < elements.length; ++i ) {
        document.getElementById( elements[ i ].id ).innerHTML = elements[ i ].html;
        eval( elements[ i ].jsCode );
    }
}

function getFormValuesAsPost() {
    var form = document.forms[ 0 ];
    var result = [];
    for( var i = 0; i < form.elements.length; ++i ) {
        if( form.elements[ i ].type == "checkbox" && !form.elements[ i ].checked )
            continue;
        result.push( form.elements[ i ].name + "=" + encodeURIComponent( form.elements[ i ].value ) );
    }
    return result.join( "&" );
}

function sendAjaxRequest( url, data, callBack, callBackParameters ) {
    var request = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject( "Microsoft.XMLHTTP" );
    var ifModifiedSince = new Date( 0 );

    request.open( "POST", url, true );
    request.setRequestHeader( "If-Modified-Since", ifModifiedSince );
    request.setRequestHeader( "Content-type", "application/x-www-form-urlencoded" );
    request.setRequestHeader( "Content-length", data.length );
    request.onreadystatechange = function() {
        if( request.readyState == 4 && request.status == 200 ) {
            if( request.responseText )
                callBack( request.responseText, callBackParameters );
        }
    }

    request.send( data );
}
function ajaxCall( action, parameters ) {
    var query = "ajax=1&" + getFormValuesAsPost();
    if( action )
        query += "&action=" + action;
    if( typeof( parameters ) != "undefined" )
        query += "&params=" + parameters;
    sendAjaxRequest( "<?php echo( $_SERVER'PHP_SELF' ] ); ?>", query, processAjaxResponse, null );
}
  </script>
<?php
$grid
->dumpHeaderCode();
?>
</head>
<body>
  <h1>Basic Ajax Demo</h1>
  <form action="" method="post">
    <div id="<?php echo( $grid->Name ); ?>_outer">
<?php $grid->dumpContents(); ?>
    </div>
  </form>
</body>
</html>