Structures_DataGrid_Renderer_Smarty

Structures_DataGrid_Renderer_Smarty -- Smarty Rendering Driver

Supported operations modes

This driver supports the following operation modes:

Таблица 57-1. Supported operations modes of this driver

ModeSupported?
Container Supportyes
Output Bufferingno
Direct Renderingno
Streamingno

Options

This driver accepts the following options:

Таблица 57-2. Options for this driver

OptionTypeDescriptionDefault Value
buildFooterboolWhether to build the footer.true
buildHeaderboolWhether to build the header.true
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()
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'
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
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()
numberAlignboolWhether to right-align numeric values.true
selfPathstringThe complete path for sorting and paging links.$_SERVER['PHP_SELF']
sortingResetsPagingboolWhether sorting HTTP queries reset paging.true

General notes

This driver does not support the render() method, it only is able to "fill" a Smarty object, by calling Smarty::assign() and Smarty::register_function().

It's up to you to called Smarty::display() after the Smarty object has been filled.

This driver assigns the following Smarty variables: - $columnSet: array of columns specifications structure: array ( 0 => array ( 'name' => field name, 'label' => column label, 'link' => sorting link, 'attributes' => attributes string, ), ... ) - $recordSet: array of records values - $currentPage: current page (starting from 1) - $recordLimit: number of rows per page - $pagesNum: number of pages - $columnsNum: number of columns - $recordsNum: number of records in the current page - $totalRecordsNum: total number of records - $firstRecord: first record number (starting from 1) - $lastRecord: last record number (starting from 1) - $currentSort: array with column names and the directions used for sorting

This driver also registers a Smarty custom function named getPaging that can be called from Smarty templates with {getPaging} in order to print paging links. This function accepts any of the Pager::factory() options as parameters.

Template example, featuring sorting and paging:

<!-- Show paging links using the custom getPaging function -->
{getPaging prevImg="<<" nextImg=">>" separator=" | " delta="5"}

<p>Showing records {$firstRecord} to {$lastRecord}
from {$totalRecordsNum}, page {$currentPage} of {$pagesNum}</p>

<table cellspacing="0">
    <!-- Build header -->
    <tr>
        {section name=col loop=$columnSet}
            <th {$columnSet[col].attributes}>
                <!-- Check if the column is sortable -->
                {if $columnSet[col].link != ""}
                    <a href="{$columnSet[col].link}">{$columnSet[col].label}</a>
                {else}
                    {$columnSet[col].label}
                {/if}
            </th>
        {/section}
    </tr>

    <!-- Build body -->
    {section name=row loop=$recordSet}
        <tr {if $smarty.section.row.iteration is even}bgcolor="#EEEEEE"{/if}>
            {section name=col loop=$recordSet[row]}
                <td {$columnSet[col].attributes}>{$recordSet[row][col]}</td>
            {/section}
        </tr>
    {/section}
</table>

This template can be used with code similar to this prototype:

$smarty = new Smarty(...);
$datagrid =& new Structures_DataGrid(...);
$datagrid->bind(...);
$datagrid->fill($smarty);
$smarty->display(PATH TO YOUR TEMPLATE);


HIVE: All information for read only. Please respect copyright!
Hosted by hive ÊÃÁ: Êèåâñêàÿ ãîðîäñêàÿ áèáëèîòåêà