I have custom component and in one of views column sorting does not work correctly. It's very weird for me. Always sort in ASC direction...
I'll introduce what I have.
Model populateState()
protected function populateState($ordering = null, $direction = null) {
// Load the filter state.
$filters = $this->getUserStateFromRequest($this->context . '.filters', 'filters', array(), 'ARRAY');
$this->setState('filters', $filters);
$conditions = $this->getUserStateFromRequest($this->context . '.conditions', 'conditions', array(), 'ARRAY');
$this->setState('conditions', $conditions);
// Load the parameters.
$params = JComponentHelper::getParams('com_ritcatalogue');
$this->setState('params', $params);
// List state information.
parent::populateState('n.node_id', 'desc');
}
as you can see by default it's sorting by column n.node_id
in DESC
direction. getListQuery()
contains:
// Add the list ordering clause.
$orderCol = $this->state->get('list.ordering', 'n.node_id');
$orderDirn = $this->state->get('list.direction', 'DESC');
$query->order($db->escape($orderCol . ' ' . $orderDirn));
also in view
$listDirn = $this->escape($this->state->get('list.ordering'));
$listOrder = $this->escape($this->state->get('list.direction'));
<input type="hidden" name="filter_order" value="<?php echo $listOrder; ?>" />
<input type="hidden" name="filter_order_Dir" value="<?php echo $listDirn; ?>" />