I think this question is a bit general, for start try to read the documentation about gridview, an play with it to understand how it works. Then come back again and ask more specific problems that you would have. Check the gridview in combination with data providers https://www.yiiframework.com/doc/guide/2.0/en/output-data-widgets
I’ve read it several times, and tried a lot but fail… I am now do it manually with pure code…
You can simply use ListView widget for this. Set required view to style one item. Set pager property to paginate by 50 items and you will get vertical list. Then style it by using CSS (e.g. Flexbox) to make it 5×10.
I agree with @mauglee This is a better way, and it will give you more flexibility how to proper display your each item.
That’s how i did this:
Controller action:
/**
* Lists all Product models.
* @return mixed
*/
public function actionIndex()
{
$curent_category = null;
if(($product_filter = Yii::$app->getRequest()->getQueryParam('ProductFilter')) !== null
&& isset($product_filter['category'])){
$active_category_id = $product_filter['category'];
//get object
$curent_category = Categories::findOne($active_category_id);
}
$products = new ProductFilter();
$dataProvider = $products->search(Yii::$app->request->queryParams);
return $this->render('index', [
'dataProvider' => $dataProvider,
'filter' => $products,
'curent_category' => $curent_category,
'company_profile' => $this->getCompany(),
]);
}
View:
<!--Products-->
<div class="row">
<div class="col-lg-12 col-md-12">
<?=
ListView::widget([
'dataProvider' => $dataProvider,
'options' => [
'tag' => 'div',
'class' => 'list-wrapper',
'id' => 'list-wrapper',
],
'layout' => '<div class="row">{items}</div><div class="row text-center">{summary}</div>', //{pager}\n{items}\n{summary}
'itemView' => function ($model, $key, $index, $widget) use ($company_profile) {
//check product price
$company_config = $company_profile->companyProductConfigurations;
//check if there is any config for specific product
foreach ($company_config as $config) {
if($config->product_id == $model->id){
//mach found
$model->checkCompanyLocalPriceConfig($config);
return $this->render('_product_item',[
'model' => $model,
'company_profile' => $company_profile
]);
}
}
$model->checkCompanyGlobalPriceConfig($company_profile);
return $this->render('_product_item',[
'model' => $model,
'company_profile' => $company_profile
]);
},
]);
?>
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 text-center">
<?= LinkPager::widget([
'pagination' => $dataProvider->pagination,
]); ?>
</div>
</div>
Thank you so much, that works!