Dear Joomla!-Developers :-)
Well, I'm working on my hobby-component "com_bestia" for quite a while and thanks to some books most things work very well.
Even the reordering and filtering works fine. Well, now I saw in com_banners that there is an other method used to include filters (JLayoutHelper::render('joomla.searchtools.default', array('view' => $this));
), so I wanted to upgrade my component aswell.
To do this I modified my view.html.php and edited a part like this:
/* State und Sorting */
$this->state = $this->get('State');
$this->sortDirection = $this->state->get('list.direction');
$this->sortColumn = $this->state->get('list.ordering');
$this->searchterms = $this->state->get('filter.search');
$this->filterForm = $this->get('FilterForm');
$this->activeFilters = $this->get('ActiveFilters');
My default.php (layout) is edited aswell:
<?php
// Den direkten Aufruf verbieten, alles andere ist unsicher
defined('_JEXEC') or die;
// Das Tooltip Behavior wird geladen
JHtml::_('behavior.tooltip');
JHtml::_('behavior.multiselect');
JHtml::_('formbehavior.chosen', 'select');
JFormHelper::addFieldPath(JPATH_COMPONENT . '/models/fields');
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));
$saveOrder = $listOrder == 'a.ordering';
$archived = $this->state->get('filter.state') == 2 ? true : false;
$trashed = $this->state->get('filter.state') == -2 ? true : false;
$params = (isset($this->state->params)) ? $this->state->params : new JObject;
?>
<script type="text/javascript">
Joomla.orderTable = function()
{
table = document.getElementById("sortTable");
direction = document.getElementById("directionTable");
order = table.options[table.selectedIndex].value;
if (order != '<?php echo $listOrder; ?>')
{
dirn = 'asc';
}
else {
dirn = direction.options[direction.selectedIndex].value;
}
Joomla.tableOrdering(order, dirn, '');
}
</script>
<?php
if ($saveOrder)
{
$saveOrderingUrl = 'index.php?option=com_bestia&task=items.saveOrderAjax&tmpl=component';
JHtml::_('sortablelist.sortable', 'itemsList', 'adminForm', strtolower($listDirn), $saveOrderingUrl);
}
$sortFields = $this->getSortFields();
?>
<form method="post" name="adminForm" id="adminForm">
<?php if (!empty( $this->sidebar)) : ?>
<div id="j-sidebar-container" class="span2">
<?php echo $this->sidebar; ?>
</div>
<div id="j-main-container" class="span10">
<?php echo JLayoutHelper::render('joomla.searchtools.default', array('view' => $this));
?>
<?php else : ?>
<div id="j-main-container">
<?php endif;?>
<div class="clearfix"> </div>
<table class="table table-bordered table-striped table-hover" id="itemsList">
<thead><?php echo $this->loadTemplate('head');?></thead>
<tfoot><?php echo $this->loadTemplate('foot');?></tfoot>
<tbody><?php echo $this->loadTemplate('body');?></tbody>
</table>
<div>
<input type="hidden" name="filter_order" value="<?php echo $listOrder; ?>" />
<input type="hidden" name="filter_order_Dir" value="<?php echo $listDirn; ?>" />
<input type="hidden" name="task" value=""/>
<input type="hidden" name="boxchecked" value="0"/>
<?php echo JHtml::_('form.token'); ?>
</div></div>
</form>
The included parts of the layout (default_head.php) looks like this:
<?php
// Den direkten Aufruf verbieten, alles andere ist unsicher
defined('_JEXEC') or die;
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));
?>
<tr>
<th width="1%" class="nowrap center hidden-phone">
<?php echo JHtml::_('grid.sort', '<i class="icon-menu-2"></i>', 'a.ordering', $listDirn, $listOrder, null, 'asc', 'JGRID_HEADING_ORDERING'); ?>
</th>
<th width="1%">
<input type="checkbox" name="checkall-toggle" value="" title="<?php echo JText::_('JGLOBAL_CHECK_ALL'); ?>"
onclick="Joomla.checkAll(this)"/>
</th>
<th width="1%" style="min-width:55px" class="nowrap center">
<?php echo JHtml::_('searchtools.sort', 'JSTATUS', 'a.state', $listDirn, $listOrder); ?>
</th>
<th>
<?php echo JHTML::_( 'searchtools.sort', 'Name', 'a.title', $this->sortDirection, $this->sortColumn); ?>
</th>
<th>
<?php echo JHTML::_( 'searchtools.sort', 'Kategorie', 'a.category', $this->sortDirection, $this->sortColumn); ?>
</th>
<th width="5%">
<?php echo JHTML::_( 'searchtools.sort', 'ID', '
a.id', $this->sortDirection, $this->sortColumn); ?>
</th>
</tr>
Well, the filtering works fine already, but if I try to sort the table by clicking on a table-heading (searchtools.sort), it sorts the table just once - and just ascending. If I click a second time, nothing changes. The little "arrow" does not change aswell.
Only the first table-heading works (a.ordering), but only if no other table-heading (like a.title) was clicked before.
What am I doing wrong here?
Thanks in advance :)