When creating a backend list view there are options to sort items by clicking on the column title Default Ordering Column

<th scope="col" style=".." class="text-center d-none d-md-table-cell">
                                <?php echo HTMLHelper::_('searchtools.sort', '', 'a.ordering', $listDirn, $listOrder, null, 'asc', 'JGRID_HEADING_ORDERING', 'icon-sort'); ?></th>

When adding searchtools.sort to one of my columns like so:

<th scope="col" style="width: 1%" class="d-none d-md-table-cell text-center">
                                <?php echo HTMLHelper::_('searchtools.sort', 'COM_COMPONENT_TABLE_TABLEHEAD_SHORTCODE_TITLE', 'a.shortcode', $listDirn, $listOrder, null, 'asc', 'JGRID_HEADING_ORDERING', 'icon-sort'); ?></th>

aswell as the respective content in the filters_view.xml:

<fields name="list">
<field name="fullordering" ...>
<option value="a.shortcode ASC">COM_COMPONENT_FILTER_SHORTCODE_ASC</option>
<option value="a.shortcode DESC">COM_COMPONENT_FILTER_SHORTCODE_DESC</option>

The list can be sorted but i have no visual indicator on the clicked column header. It just "stays" like its not sorted at all. ShortCode has been clicked

Even the examples I've found in the web has the same "issue" on the visible side. When using the title column in the same view it works for this column but not for "non-default" columns.

I've already seen that there is a method in the HTMLView called "getSortFields" but even when adding there my column in the array it doesn't change anything:

protected function getSortFields(): array
        return [
            'a.published'    => Text::_('JSTATUS'),
            'a.title'         => Text::_('JGLOBAL_TITLE'),
            'a.id'           => Text::_('JGRID_HEADING_ID'),
            'a.group_id'    => Text::_('COM_COMPONENT_TABLE_TABLEHEAD_GROUPID_TITLE'),

What I am missing here?

  • 1
    This is controlled solely by values passed to HTMLHelper::_('searchtools.sort'). It means $listOrder/$listDirn aren't populated correctly.
    – Sharky
    Commented Nov 15, 2023 at 9:47
  • 1
    Make sure your fields are all named consistently among your model query, your filter fields ordering field, and the third parameter in the HTMLHelper::_('searchtools.sort',..) call. Switch on Joomla debug and use the debug panel to examine the Session data - in particular the registry array, list.fullordering element. If you've coded things correctly then you should get the little sort icon set to icon-caret-up or icon-caret-down on the column you've ordered by, and its associated heading element should have id="sorted", so you can style that as you please. Commented Nov 15, 2023 at 12:55

1 Answer 1


This is an example from a View of mine where the HTMLView class gets the List Order and Direction values

$this->listOrder  = $this->escape($this->state->get('list.ordering'));
$this->listDirn   = $this->escape($this->state->get('list.direction'));

and in the /tmpl folder the values are added to the table column headings

<th class='left'>
    <?php echo HTMLHelper::_('searchtools.sort',  'JGRID_HEADING_ID', 'a.id', $this->listDirn, $this->listOrder); ?>

More commonly you would find examples of $listOrder and $ListDirn being set in the top of the /tmpl file rather than using the $this to pass them across from the HTML View class.

This allows people to click on the column headings to change the sort column and order. I rarely use the Sort option of the filter_view.xml, I find it cumbersome to maintain and not that intuitive for the end user.

The columns that you wish to sort on must also appear in the Model as part of the __construct

    public function __construct($config = array())
        if (empty($config['filter_fields']))
            $config['filter_fields'] = array(
                'id', 'a.`id`',

Although the property is filter_fields you will also find if the column(s) you want to sort on does not appear in this array then you will not be able to sorting on that column(s).

  • that was the issue, the columns where not listed in the $config['filter_fields] array.
    – Marco
    Commented Nov 19, 2023 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.