http://nerburish.com/yii2-matchheight-listview-widget/ en 🇪🇸, (*1)
ListView widget improved to use Jquery MatchHeight.js (http://brm.io/jquery-match-height/), (*2)
Demo Screenshot:
, (*3)
Installation
The preferred way to install this extension is through composer., (*4)
Either run, (*5)
php composer.phar require --prefer-dist nerburish/yii2-match-height-view "dev-master"
or add, (*6)
"nerburish/yii2-match-height-view": "dev-master"
to the require section of your composer.json
file., (*7)
Usage
The usage is similar to default ListView Widget (http://www.yiiframework.com/doc-2.0/yii-widgets-listview.html), (*8)
You just need a dataProvider and prepare the item template for your model., (*9)
In clientOptions you can pass the MatchHeight.js options to modify the plugin behavior (see https://github.com/liabru/jquery-match-height#options), (*10)
You can also attach a cssFile for styling the grid., (*11)
Exemple:, (*12)
We have this model:, (*13)
class MyModel extends \yii\base\Theme
{
public $id;
public $title;
public $description;
}
And this item template named _item.php:, (*14)
<h3><?= $model->title ?></h3>
<p><?= $model->description ?></p>
Then in our view, we run the widget:, (*15)
<?php echo \nerburish\matchheight\MatchHeightView::widget([
'dataProvider' => $dataProvider,
'itemView' => '_item',
'cssFile' => [
"@web/css/grid-demo.css"
]
]) ?>
The css used for the demo:, (*16)
/* ---- grid ---- */
.grid {
box-sizing: border-box;
}
/* clearfix */
.grid:after {
content: '';
display: block;
clear: both;
}
/* ---- grid-item ---- */
.grid-item {
width: 24%;
padding: 10px;
margin: 0.5%;
float: left;
background: #e4e4e4;
border-radius: 5px;
}
You may also be interested in Masonry.js ListView widget: https://github.com/nerburish/yii2-masonry-view, (*17)