dev-master
9999999-devListView widget improved to use Isotope (http://isotope.metafizzy.co/)
MIT
The Requires
- yiisoft/yii2 *
- bower-asset/isotope *
by nerburish
extension yii2 widget view dataprovider listview isotope masonry
ListView widget improved to use Isotope (http://isotope.metafizzy.co/)
Yii2 widget to extend the Yii2 ListView for use it as Isotope grid (http://isotope.metafizzy.co/), (*1)
Widget demo screenshot: , (*2)
The preferred way to install this extension is through composer., (*3)
Either run, (*4)
php composer.phar require --prefer-dist nerburish/yii2-isotope-view "dev-master"
or add, (*5)
"nerburish/yii2-isotope-view": "dev-master"
to the require section of your composer.json
file., (*6)
The usage is similar to default ListView Widget (http://www.yiiframework.com/doc-2.0/yii-widgets-listview.html), (*7)
You just need a dataProvider and prepare the item template for your model., (*8)
In clientOptions you can pass the Isotope options to modify the plugin behavior (see http://isotope.metafizzy.co/options.html), (*9)
The filterAttribute parameter is the attribute name of the model passed that will be used as class for the grid-item tag. The attribute value can be an array or string of separated by spaces., (*10)
You can also attach a cssFile for styling the grid., (*11)
We have this model:, (*12)
class MyElement extends \yii\base\Model { public $id; public $name; public $symbol; public $number; public $weight; public $categories; }
And this item template named _item.php:, (*13)
<h5 class="name"><?= $model->name ?></h5> <p class="symbol"><?= $model->symbol ?></p> <p class="number"><?= $model->number ?></p> <p class="weight"><?= $model->weight ?></p>
Finally, in our view, we run the widget:, (*14)
<?php echo \nerburish\isotopeview\IsotopeView::widget([ 'dataProvider' => $dataProvider, 'filterAttribute' => 'categories', 'itemView' => '_item', 'clientOptions' => [ 'layoutMode' => 'masonry', ], 'cssFile' => [ "@web/css/grid-demo.css" ] ]) ?>
All models, views and CSS styles used for the exemple are inside the folder demo-data. The template named index.php adds a filter buttons to test the filtering methods. It's a similar exemple that it's explained inside the Isotope documentation (http://isotope.metafizzy.co/filtering.html), (*15)
registerJs(' var filterFns = { // show if number is greater than 50 numberGreaterThan50: function() { var number = $(this).find(".number").text(); return parseInt( number, 10 ) > 50; }, // show if name ends with -ium ium: function() { var name = $(this).find(".name").text(); return name.match( /ium$/ ); } }; $(".filters-button-group").on( "click", "button", function() { var filterValue = $( this ).attr("data-filter"); // use filterFn if matches value filterValue = filterFns[ filterValue ] || filterValue; $("#w0 .grid").isotope({ filter: filterValue }); }); ', $this::POS_END) ?> $dataProvider, 'filterAttribute' => 'categories', 'itemView' => '_item', 'cssFile' => [ "@web/css/grid-demo.css" ] ]) ?>
You may also be interested in MatchHeight.js ListView widget: https://github.com/nerburish/yii2-match-height-view, (*16)
ListView widget improved to use Isotope (http://isotope.metafizzy.co/)
MIT
extension yii2 widget view dataprovider listview isotope masonry