/** * Set datasource * * @return void */ protected function _setDataSource() { $this->_dataSource = $this->_model->queryBuilder(); foreach ($this->_joins as $table) { $this->_dataSource->columnsJoinOne($table); } $this->_dataSource->columns($this->_columns); foreach ($this->_conditions as $cond) { if (is_array($cond)) { $this->_dataSource->addWhere($cond['cond'], $cond['params']); } else { $this->_dataSource->addWhere($cond); } } $sort = $this->_grid->getSortKey(); if (null === $sort) { $sort = $this->_model->getOrderExpr(); } $direction = $this->_grid->getSortDirection(); if (null === $direction) { $direction = $this->_model->getOrderAsc() ? "ASC" : "DESC"; } if ($sort) { $alias = $this->_dataSource->getCorrelationName($sort); if ($alias) { $sort = $alias . "." . $sort; } if ($direction) { $this->_dataSource->orderBy($sort . ' ' . $direction); } else { $this->_dataSource->orderBy($sort); } } }
/** * Return current grid sort direction param. * * @return string */ public function getSortDirection() { if ($this->isSorted()) { return $this->_grid->getSortDirection(); } return $this->_sortDirection; }