Gridconhtmlypager
De CidesaWiki
Esta explicación funciona para modulos generados con el propel-admin. Este código se encuentra en el módulo "nomjorlablot" de la aplicación de nómina de Siga Software Libre.
- Se debe generar el objeto Pager en el Acction.class
public function executeEdit()
{
$c = new Criteria();
$this->pagerNphojint = NphojintPeer::getPagerByCriteria($c,$this->getRequestParameter('page',1));
parent::executeEdit();
}
la función NphojintPeer::getPagerByCriteria() fue generada para que hiciera la consulta a la base de datos y retornada el objeto Pager.
- Se pasa a través del editSuccess.php la variable pagerNphojint del ejemplo al objeto parcial (en este caso _edit_form.php).
<?php include_partial('nomjorlablot/edit_form', array('npdefjorlab' => $npdefjorlab, 'labels' => $labels, 'pagerNphojint' => $pagerNphojint)) ?>
- Se debe colocar en el _edit_form.php el siguiente codigo para generar la nueva tabla.
</fieldset>
<!-- Modifique estas variables y luego coloque las columnas y registros que desee -->
<?php $tituloTabla = __('Datos del Permiso'); ?>
<?php $pagerTabla = $pagerNpfalper; ?>
<?php $modulo = $sf_context->getModuleName(); ?>
<?php $accion = 'edit'; ?>
<fieldset>
<legend><?php echo $tituloTabla; ?></legend>
<table border="0" class="sf_admin_list">
<thead>
<tr>
<!-- Nombre de las Columnas -->
<th><?php echo NpfalperPeer::getColumName(NpfalperPeer::FECDES ) ?></th>
<th><?php echo NpfalperPeer::getColumName(NpfalperPeer::FECHAS ) ?></th>
<th><?php echo NpfalperPeer::getColumName(NpfalperPeer::CODMOT ) ?></th>
<th><?php echo NpfalperPeer::getColumName(NpmotfalPeer::DESMOTFAL ) ?></th>
</tr>
</thead>
<tbody>
<?php $i = 1; foreach ($pagerTabla->getResults() as $registro): $odd = fmod(++$i, 2) ?>
<tr class="sf_admin_row_<?php echo $odd ?>">
<!-- Registros de la tabla -->
<td><?php echo $registro->getFecdes() ?></td>
<td><?php echo $registro->getFechas() ?></td>
<td><?php echo $registro->getCodmot() ?></td>
<td><?php echo $registro->getDesmotfal() ?></td>
</tr>
<?php endforeach; ?>
</tbody>
<tfoot>
<tr><th colspan="5">
<div class="float-right">
<?php if ($pagerTabla->haveToPaginate()): ?>
<?php echo link_to(image_tag(sfConfig::get('sf_admin_web_dir').'/images/first.png', array('align' => 'absmiddle', 'alt' => __('First'), 'title' => __('First'))), $modulo.'/'.$accion.'?page=1') ?>
<?php echo link_to(image_tag(sfConfig::get('sf_admin_web_dir').'/images/previous.png', array('align' => 'absmiddle', 'alt' => __('Previous'), 'title' => __('Previous'))), $modulo.'/'.$accion.'?page='.$pagerTabla->getPreviousPage()) ?>
<?php foreach ($pagerTabla->getLinks() as $page): ?>
<?php echo link_to_unless($page == $pagerTabla->getPage(), $page, $modulo.'/list?page='.$page) ?>
<?php endforeach; ?>
<?php echo link_to(image_tag(sfConfig::get('sf_admin_web_dir').'/images/next.png', array('align' => 'absmiddle', 'alt' => __('Next'), 'title' => __('Next'))), $modulo.'/'.$accion.'?page='.$pagerTabla->getNextPage()) ?>
<?php echo link_to(image_tag(sfConfig::get('sf_admin_web_dir').'/images/last.png', array('align' => 'absmiddle', 'alt' => __('Last'), 'title' => __('Last'))), $modulo.'/'.$accion.'?page='.$pagerTabla->getLastPage()) ?>
<?php endif; ?>
</div>
<?php echo format_number_choice('[0] '.__('no result').'|[1] 1 '.__('result').'|(1,+Inf] %1% '.__('results'), array('%1%' => $pagerTabla->getNbResults()), $pagerTabla->getNbResults()) ?>
</th></tr>
</tfoot>
</table>
</fieldset>
- <thead> marca la cabecera de la tabla, alli se debe colocar la información de los nombres de campos a colocar en la tabla (nombre de columnas). Este nombre de columnas fueron colcoadas en la clase NphojintPeer::getColumName(NphojintPeer::CEDEMP). Esta funcion fue creada de la siguiente forma en la clase NphojintPeer:
const COLUMNS = 'columns';
private static $columsname = array (
self::COLUMNS => array (NphojintPeer::CEDEMP => 'Cedula', NphojintPeer::NOMEMP => 'Nombre', NphojintPeer::ID => 'Id', ),);
static public function getColumName($colum)
{
return self::$columsname[self::COLUMNS][$colum];
}
- <tbody> muestra los registros de la tabla. Hay que tomar en cuenta que el Pager tiene la información de paginada, y hay que colocar los registros de objetos html que necesitemos, en este caso la primera celda de cada registro de la tabla tiene un checkbox delante.
<td><?php echo checkbox_tag($Nphojint->getId(),'1',false) ?></td>
- En <tfoot> se colocan los links para el paginador, << < 1 2 3 > >>, los cuales manejan las paginas de la tabla.
- TODO: Como manejar los objetos html dentro de la tabla para guardarlos o manejarlos.
- Listo.............