Я взял взят из решения сложения по этой ссылке, но возвращает (без значения) для каждой строки.
В модели Sistop.php:
Код: Выделить всё
public function getDiff()
{
$this->diff = 0;
if (is_numeric($this->qdsistop) && is_numeric($this->qusistop)) {
$this->diff = $this->qdsistop - $this->qusistop;
}
return $this->diff;
}
Код: Выделить всё
class SistopSearch extends Sistop
{
public function attributes()
{
return array_merge(parent::attributes(), ['diff']);
}
......
public function search($params)
{
$query = Sistop::find()->select('*, (`qdsistop` - `qusistop`) AS `diff`');
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
// enable sorting for the related columns
$dataProvider->sort->attributes['diff'] = [
'asc' => ['diff' => SORT_ASC],
'desc' => ['diff' => SORT_DESC],
];
.....
if (is_numeric($this->diff)) {
$query->having([
'diff' => $this->diff,
]);
}
Заранее спасибо.
Подробнее здесь: https://stackoverflow.com/questions/606 ... wo-columns
Мобильная версия