Structures_DataGrid_Renderer_Smarty

Structures_DataGrid_Renderer_Smarty -- Smarty Rendering Driver

Supported operations modes

This driver supports the following operation modes:

Options

This driver accepts the following options:

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

Option Type Description Default Value
buildFooter bool Whether to build the footer. true
buildHeader bool Whether to build the header. true
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()
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'
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
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
selfPath string The complete path for sorting and paging links. $_SERVER['PHP_SELF']
sortingResetsPaging bool Whether 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);

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