Structures_DataGrid_Renderer_HTMLTable

Structures_DataGrid_Renderer_HTMLTable – HTML Table Rendering Driver

Описание

Driver for rendering the DataGrid as an HTMLTable

Supported operations modes

This driver supports the following operation modes:

Supported operations modes of this driver
Mode Supported?
Container Support yes
Output Buffering yes
Direct Rendering no
Streaming no
Object Preserving no

Options

This driver accepts the following options:

Options for this driver
Option Type Описание Default Value
buildFooter bool Whether to build the footer. true
buildHeader bool Whether to build the header. true
classASC string A CSS class name for TH elements to define that sorting is currently ascending. ''
classDESC string A CSS class name for TH elements to define that sorting is currently descending. ''
columnAttributes array Column cells attributes. This is an array of the form: array(fieldName => array(attribute => value, ...) ...) This option is only used by XML/HTML based drivers. array()
convertEntities bool Whether or not to convert html entities. This calls htmlspecialchars(). true
defaultCellValue string What value to put by default into empty cells. null
defaultColumnValues array Per-column default cell value. This is an array of the form: array(fieldName => value, ...). array()
emptyRowAttributes array An associative array containing the attributes for empty rows. array()
encoding string The content encoding. If the mbstring extension is present the default value is set from mb_internal_encoding(), otherwise it is ISO-8859-1. 'ISO-8859-1'
evenRowAttributes array An associative array containing each attribute of the even rows. array()
excludeVars array Variables to be removed from the generated HTTP queries. array()
extraVars array Variables to be added to the generated HTTP queries. array()
fillWithEmptyRows bool Ensures that all pages have the same number of rows. false
headerAttributes array Attributes for the header row. This is an array of the form: array(attribute => value, ...) array()
hideColumnLinks array By default sorting links are enabled on all columns. With this option it is possible to disable sorting links on specific columns. This is an array of the form: array(fieldName, ...). This option only affects drivers that support sorting. array()
numberAlign bool Whether to right-align numeric values. true
oddRowAttributes array An associative array containing each attribute of the odd rows. array()
onMove string Name of a Javascript function to call on onclick/onsubmit events when the user is either paging or sorting the data. This function receives a single object argument of the form: { page: <page>, sort: [{field: <field>, direction: <direction>}, ...], data: <user_data> }. Remark: setting this option doesn't remove the href attribute, you should return false from your handler function to void it (eg: for AJAX, etc..). null
onMoveData string User data passed in the "data" member of the object argument passed to onMove. No JSON serialization is performed, this is assigned as a raw string to the "data" attribute. It's up to you to add quotes, slashes, etc... ''
selfPath string The complete path for sorting and paging links. $_SERVER['PHP_SELF']
sortIconASC string The icon to define that sorting is currently ascending. Can be text or HTML to define an image. ''
sortIconDESC string The icon to define that sorting is currently descending. Can be text or HTML to define an image. ''
sortingResetsPaging bool Whether sorting HTTP queries reset paging. true

Examples

Simple AJAX support using the Prototype framework

<?php
require_once 'PEAR.php';
require_once 
'Structures/DataGrid.php';    

$datagrid =& new Structures_DataGrid(10);

$options['dsn'] = 'mysql://username@localhost/mydatabase';
$datagrid->bind("SELECT * FROM mytable"$options);

// Set the javascript handler function for onclick events
$datagrid->setRendererOption('onMove''updateGrid'true);

if (isset(
$_GET['ajax'])) {
    
// Handle table AJAX requests 
    
if ($_GET['ajax'] == 'table') {
        
$datagrid->render();
    }
    
// Handle pager AJAX requests 
    
if ($_GET['ajax'] == 'pager') {
        
$datagrid->render('Pager');
    }
    exit();
}

// No AJAX request, render the initial content..
?>
<html>

<head>
<!-- Require the Prototype JS framework from http://www.prototypejs.org -->
<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript">
function updateGrid(info) 
{
    var url = '<?php echo $_SERVER['PHP_SELF']; ?>';
    var pars = 'page=' + info.page;
    if (info.sort.length > 0) {
        pars += '&orderBy=' + info.sort[0].field + '&direction=' + info.sort[0].direction;
    }
        
    new Ajax.Updater( 'grid', url, { method: 'get', parameters: pars + '&ajax=table' });
    new Ajax.Updater( 'pager', url, { method: 'get', parameters: pars + '&ajax=pager' });

    // Important: return false to avoid href links
    return false;
}
</script>
</head>

<body>
Pages: <span id="pager"><?php $datagrid->render('Pager'); ?></span>
<div id="grid"><?php $datagrid->render(); ?></div>
</body>

</html>
    Поддержать сайт на родительском проекте КГБ