Back to Grid class

Method sort

public static string
sort
(mixed $title, mixed $order, mixed $direction = 'asc', mixed $selected = '', mixed $task = null, mixed $newDirection = 'asc', mixed $tip = '', mixed $form = null)
Method to sort a column in a grid
Parameters
  • string $title The link title
  • string $order The order field for the column
  • string $direction The current direction
  • string $selected The selected ordering
  • string $task An optional task override
  • string $newDirection An optional direction for the new column
  • string $tip An optional text shown as tooltip title instead of $title
  • string $form An optional form selector
Returns
  • string
Since
  • 1.5
Class: Grid
Project: Joomla

Method sort - Source code

/**
 * Method to sort a column in a grid
 *
 * @param   string  $title         The link title
 * @param   string  $order         The order field for the column
 * @param   string  $direction     The current direction
 * @param   string  $selected      The selected ordering
 * @param   string  $task          An optional task override
 * @param   string  $newDirection  An optional direction for the new column
 * @param   string  $tip           An optional text shown as tooltip title instead of $title
 * @param   string  $form          An optional form selector
 *
 * @return  string
 *
 * @since   1.5
 */
public static function sort($title, $order, $direction = 'asc', $selected = '', $task = null, $newDirection = 'asc', $tip = '', $form = null)
{
    HTMLHelper::_('behavior.core');
    HTMLHelper::_('bootstrap.popover', '.hasPopover', ['trigger' => 'hover focus']);
    $direction = strtolower($direction);
    $icon = array('arrow-up-3', 'arrow-down-3');
    $index = (int) ($direction === 'desc');
    if ($order != $selected) {
        $direction = $newDirection;
    } else {
        $direction = $direction === 'desc' ? 'asc' : 'desc';
    }
    if ($form) {
        $form = ', document.getElementById(\'' . $form . '\')';
    }
    $html = '<a href="#" onclick="Joomla.tableOrdering(\'' . $order . '\',\'' . $direction . '\',\'' . $task . '\'' . $form . ');return false;"' . ' class="hasPopover" title="' . htmlspecialchars(Text::_($tip ?: $title)) . '"' . ' data-bs-content="' . htmlspecialchars(Text::_('JGLOBAL_CLICK_TO_SORT_THIS_COLUMN')) . '" data-bs-placement="top">';
    if (isset($title['0']) && $title['0'] === '<') {
        $html .= $title;
    } else {
        $html .= Text::_($title);
    }
    if ($order == $selected) {
        $html .= '<span class="icon-' . $icon[$index] . '"></span>';
    }
    $html .= '</a>';
    return $html;
}