Answer the question
In order to leave comments, you need to log in
Yii2 gridview how to get number of rows?
There is a GridView (kartik) table, data is displayed in one of the columns:
[
'attribute' => 'var',
'value' => 'var.full_name',
// 'width'=>'10%',
'label' => Yii::t('admin', 'Название'),
'content' => function ($data) {
$good_var = \app\modules\catalog\models\GoodsVar::find()->select(['full_name'])->where(['id' => $data->var_id])->asArray()->One();
if (!empty($good_var['full_name'])) {
return $good_var['full_name'];
} else {
return '<p style="color: #ff3b36;">Отсутствует</p>';
}
},
'format' => 'raw',
],
Answer the question
In order to leave comments, you need to log in
1. gridview has pagination. Do you need the number of non-empty lines for the current page or for the entire database?
2. what for 'value'=> 'var.full_name',
if then to redefine a content?
3. You should not make requests from the view, there is a controller for this, but apparently this is related data, which means it is worth assigning it to the model.
Depending on how it will be used. If you just display somewhere the number of empty lines on the current page, then perhaps it's easier to write 2 lines of jquery?
But you can also use php. Or take out the logic in the model or make your own ActiveDataProvider and put the method there.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question