Сортировка столбцов бэкэнд работает неправильно
У меня есть пользовательский компонент, и в одной из сортировок сортировка столбцов работает неправильно. Это очень странно для меня. Всегда сортируйте в направлении ASC ...
Я расскажу, что у меня есть.
Модель 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');
}
, как вы можете видеть по умолчанию, он сортирует по столбцу n.node_id
в DESC
. getListQuery()
содержит:
// 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));
также в поле зрения
$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 ответа
1
Решено ... Это была моя простая ошибка.
У меня был
$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; ?>" />
вместо
$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; ?>" />
, где направление упорядочивало колонку и столбец было направлением (неправильные параметры в get ())
ответил turson 23 J0000006Europe/Moscow 2015, 10:29:01
0
Попробуйте следующее:
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-файл:
<field
name="fullordering"
type="list"
label="Give label name"
description="Give description name"
onchange="this.form.submit();"
default="n.node_id DESC"
>
ответил Jextn 22 J0000006Europe/Moscow 2015, 15:12:06