Table-Sorting does not work correctly

259 views
Skip to first unread message

Timotheus Titus

unread,
Mar 28, 2014, 7:40:19 AM3/28/14
to joomla-de...@googlegroups.com
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 :)


Bildschirmfoto 2014-03-28 um 12.02.37.png

Timotheus Titus

unread,
Mar 28, 2014, 11:25:02 AM3/28/14
to joomla-de...@googlegroups.com
I created a little video to demonstrate what I mean.

https://www.youtube.com/watch?v=fmLmcV9BfBs&feature=youtube_gdata_player

Timotheus Titus

unread,
Mar 28, 2014, 11:40:44 AM3/28/14
to joomla-de...@googlegroups.com
I solved it :-)

I compared the layout-file to the layout-file of com_banners and saw, that there is a part in my file, which is missing in the com_banners Layout-File:



        <input type="hidden" name="filter_order" value="<?php echo $listOrder; ?>" />
        <input type="hidden" name="filter_order_Dir" value="<?php echo $listDirn; ?>" />

I removed it and now it works :-)


Well, a little "bug" is still in it at this moment: If I click some table-heading, there is a little arrow appearing. This works in every case but not in the case of the "Categories"-Row. The categories are sorting, but there is no arrow.



Am Freitag, 28. März 2014 12:40:19 UTC+1 schrieb Timotheus Titus:
Reply all
Reply to author
Forward
0 new messages