Bonjour, je viens de mettre place l'affichage d'une table avec des colonne triable mais le problème se situe au niveau de la pagination car quand je navigue d'une page à l'autre l'affichage se remet avec l'affichage par défaut c'est à dire sur la date et tri décroissant.
Mon modèle :
Ma vue :
Mon affichage :
Est ce que quelqu'un à déjà eu se problème ? ou y a t'il un tuto pour régler cela ?
Mon modèle :
Code PHP:
<?php
defined('_JEXEC') or die;
jimport('joomla.application.component.modellist');
class GagnantsmagnumModelGagnants extends JModelList {
public function __construct($config = array()) {
parent::__construct($config);
}
protected function populateState($ordering = null, $direction = null) {
// Initialise variables.
$app = JFactory::getApplication();
// List state information
$limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit'));
$this->setState('list.limit', $limit);
$limitstart = JRequest::getVar('limitstart', 0, '', 'int');
$this->setState('list.start', $limitstart);
$filter_order = JRequest::getCmd('filter_order','a.date_gain');
$filter_order_Dir = JRequest::getCmd('filter_order_Dir','DESC');
$this->setState('filter_order', $filter_order);
$this->setState('filter_order_Dir', $filter_order_Dir);
// List state information.
parent::populateState();
}
protected function getListQuery() {
// Create a new query object.
$db = JFactory::getDbo();
$query = $db->getQuery(true);
// Select the required fields from the table.
$query->select(
$this->getState(
'list.select', 'a.*'
)
);
$query->from('`#__gagnantsmagnum_gagnants` AS a');
// Filter by published state
$published = $this->getState('filter.state');
if (is_numeric($published)) {
$query->where('a.state = '.(int) $published);
} else if ($published === '') {
$query->where('(a.state IN (0, 1))');
}
$query->order($db->getEscaped($this->getState('filter_order')) . ' ' . $db->getEscaped($this->getState('filter_order_Dir')));
//$query->order('a.date_gain DESC');
echo $query;
return $query;
}
}
Code PHP:
<?php
// No direct access
defined('_JEXEC') or die;
jimport('joomla.application.component.view');
class GagnantsmagnumViewGagnants extends JView
{
protected $items;
protected $pagination;
protected $state;
protected $params;
public function display($tpl = null)
{
$app = JFactory::getApplication();
$this->state = $this->get('State');
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->params = $app->getParams('com_gagnantsmagnum');
// Check for errors.
if (count($errors = $this->get('Errors'))) {
JError::raiseError(500, implode("\n", $errors));
return false;
}
$this->sortDirection = $this->state->get('filter_order_Dir');
$this->sortColumn = $this->state->get('filter_order');
//echo $this->sortColumn;
$this->_prepareDocument();
parent::display($tpl);
}
}
Code PHP:
<?php
defined('_JEXEC') or die;
?>
<?php if($this->items) : ?>
<form id="adminForm" action="<?php echo JRoute::_( 'index.php' );?>" method="post" name="adminForm">
<table width="100%" border="0">
<tr>
<th><?php echo JHTML::_( 'grid.sort', 'Date', 'a.date_gain', $this->sortDirection, $this->sortColumn); ?></th>
<th><?php echo JHTML::_( 'grid.sort', 'Prenom', 'a.prenom', $this->sortDirection, $this->sortColumn); ?></th>
<th><?php echo JHTML::_( 'grid.sort', 'Nom', 'a.nom', $this->sortDirection, $this->sortColumn); ?></th>
<th><?php echo JHTML::_( 'grid.sort', 'CP et ville', 'a.cp_et_ville', $this->sortDirection, $this->sortColumn); ?></th>
<th><?php echo JHTML::_( 'grid.sort', 'Cadeau', 'a.nom_du_cadeau', $this->sortDirection, $this->sortColumn); ?></th>
</tr>
<?php foreach ($this->items as $item) :?>
<tr>
<th><?php echo date("d/m/y", strtotime($item->date_gain)); ?></th>
<th><?php echo $item->prenom; ?></th>
<th><?php echo $item->nom; ?></th>
<th><?php echo $item->cp_et_ville; ?></th>
<th><?php echo $item->nom_du_cadeau; ?></th>
</tr>
<?php endforeach; ?>
<?php //echo $this->sortColumn; ?>
</table>
<input type="hidden" name="filter_order" value="<?php echo $this->sortColumn; ?>" />
<input type="hidden" name="filter_order_Dir" value="<?php echo $this->sortDirection; ?>" />
</form>
<div class="pagination">
<?php if ($this->params->def('show_pagination_results', 1)) : ?>
<p class="counter" style="border:0 none!important;">
<?php echo $this->pagination->getPagesCounter(); ?>
</p>
<?php endif; ?>
<?php echo $this->pagination->getPagesLinks(); ?>
</div>
<?php else : ?>
<h1> Pas d'informations disponibles </h1>
<?php endif; ?>
Commentaire