2

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; ?>" />

2 Answers 2

1

Solved... It was my simple fault.

In view I had

$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; ?>" />

instead of

$listDirn = $this->escape($this->state->get('list.direction'));
$listOrder = $this->escape($this->state->get('list.ordering'));
<input type="hidden" name="filter_order" value="<?php echo $listOrder; ?>" />
<input type="hidden" name="filter_order_Dir" value="<?php echo $listDirn; ?>" />

where direction was ordering column and column was direction (wrong parameters in get())

0

Try this:

protected function populateState($ordering = null, $direction = null) {
parent::populateState('n.node_id', 'desc');
}

getlistquery:

$orderCol = $this->state->get('list.ordering', 'n.node_id');
$orderDirn = $this->state->get('list.direction', 'desc');

xml file:

<field
      name="fullordering"
      type="list"
      label="Give label name"
      description="Give description name"
      onchange="this.form.submit();"
      default="n.node_id DESC"
   >
8
  • Doesn't change anything
    – turson
    Commented Jun 22, 2015 at 12:21
  • Now try it and check your backend
    – Jextn
    Commented Jun 22, 2015 at 12:24
  • Thanks for your reply but same again... For me it's very weird because I have written a lot of views and only here is this problem
    – turson
    Commented Jun 22, 2015 at 12:38
  • Please refer this site docs.joomla.org/… you can find some solution.
    – Jextn
    Commented Jun 22, 2015 at 12:45
  • 1
    I have already read this article. Joomla always sort in ASC direction when I click on column header. Moreover there is no "filter image" next to header
    – turson
    Commented Jun 23, 2015 at 6:58

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.