Structures_DataGrid_Renderer_CheckableHTMLTable

Structures_DataGrid_Renderer_CheckableHTMLTable -- HTML table rendering driver with a checkbox for each row of the grid

Availability

This driver is experimental and has not been officially released yet. It is only available from CVS.

Description

Driver for rendering the DataGrid as an HTML table with a checkbox for each row

Supported operations modes

This driver supports the following operation modes:

Table 59-1. Supported operations modes of this driver

ModeSupported?
Container Supportyes
Output Bufferingyes
Direct Renderingno
Streamingno
Object Preservingno

Options

This driver accepts the following options:

Table 59-2. Options for this driver

OptionTypeDescriptionDefault Value
buildFooterboolWhether to build the footer.true
buildHeaderboolWhether to build the header.true
classASCstringA CSS class name for TH elements to define that sorting is currently ascending.''
classDESCstringA CSS class name for TH elements to define that sorting is currently descending.''
columnAttributesarrayColumn 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()
convertEntitiesboolWhether or not to convert html entities. This calls htmlspecialchars().true
defaultCellValuestringWhat value to put by default into empty cells.null
defaultColumnValuesarrayPer-column default cell value. This is an array of the form: array(fieldName => value, ...).array()
emptyRowAttributesarrayAn associative array containing the attributes for empty rows.array()
encodingstringThe 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'
evenRowAttributesarrayAn associative array containing each attribute of the even rows.array()
excludeVarsarrayVariables to be removed from the generated HTTP queries.array()
extraVarsarrayVariables to be added to the generated HTTP queries.array()
fillWithEmptyRowsboolEnsures that all pages have the same number of rows.false
formobjectInstance of a HTML_QuickForm object.null
formRendererobjectInstance of a HTML_QuickForm_Renderer_QuickHtml object.null
headerAttributesarrayAttributes for the header row. This is an array of the form: array(attribute => value, ...)array()
hideColumnLinksarrayBy 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()
inputNamestringThe HTML_QuickForm element name for the checkboxes.'checkedItems'
numberAlignboolWhether to right-align numeric values.true
oddRowAttributesarrayAn associative array containing each attribute of the odd rows.array()
onMovestringName 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
onMoveDatastringUser 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...''
primaryKeystringThe name of the primary key. This value is used for the checkboxes.'id'
selfPathstringThe complete path for sorting and paging links.$_SERVER['PHP_SELF']
sortIconASCstringThe icon to define that sorting is currently ascending. Can be text or HTML to define an image.''
sortIconDESCstringThe icon to define that sorting is currently descending. Can be text or HTML to define an image.''
sortingResetsPagingboolWhether sorting HTTP queries reset paging.true

General notes

This driver puts a checkbox for each row of the table into the first column. By default, a new column with the value of the 'inputName' option is added for the checkboxes. If you want to customize this column, you can add a column yourself as it is shown in the example.

Examples

Example 59-1. Basic usage

<?php
require_once 'HTML/QuickForm.php';
require_once 'HTML/QuickForm/Renderer/QuickHtml.php';
require_once 'Structures/DataGrid.php';

// prepare the form and the QuickHtml renderer
$form =& new HTML_QuickForm();
$renderer =& new HTML_QuickForm_Renderer_QuickHtml();

// add action selectbox and submit button to the form
$form->addElement('select', 'action', 'choose',
                  array('delete' => 'Delete',
                        'move'   => 'Move to archive'));
$form->addElement('submit', 'submit', 'Save');

// prepare the DataGrid
$dg =& new Structures_DataGrid();
if (PEAR::isError($dg)) {
   die($dg->getMessage() . '<br />' . $dg->getDebugInfo());
}

// bind some data (e.g. via a SQL query and MDB2)
$error = $dg->bind('SELECT * FROM news',
                   array('dsn' => 'mysql://user:password@server/database'));
if (PEAR::isError($error)) {
   die($error->getMessage() . '<br />' . $error->getDebugInfo());
}

// the renderer adds an auto-generated column for the checkbox by default;
// it is also possible to add a column yourself, for example like in the
// following four lines:
$column = new Structures_DataGrid_Column('checkboxes', 'idList', null,
                                         array('width' => '10'));
$dg->addColumn($column);
$dg->generateColumns();

$rendererOptions = array('form'         => $form,
                         'formRenderer' => $renderer,
                         'inputName'    => 'idList',
                         'primaryKey'   => 'id'
                        );

// use a template string for the form
$tpl = '';

// generate the HTML table and add it to the template string
$tpl .= $dg->getOutput('CheckableHTMLTable', $rendererOptions);
if (PEAR::isError($tpl)) {
   die($tpl->getMessage() . '<br />' . $tpl->getDebugInfo());
}

// add the HTML code of the action selectbox and the submit button to the
// template string
$tpl .= $renderer->elementToHtml('action');
$tpl .= $renderer->elementToHtml('submit');

// we're now ready to output the form (toHtml() adds the <form> / </form>
// pair to the template)
echo $renderer->toHtml($tpl);

// if the form was submitted and the data is valid, show the submitted data
if ($form->isSubmitted() && $form->validate()) {
    var_dump($form->getSubmitValues());
}
?>