2017 © Pedro Peláez
 

yii2-extension yii2-isotope-view

ListView widget improved to use Isotope (http://isotope.metafizzy.co/)

image

nerburish/yii2-isotope-view

ListView widget improved to use Isotope (http://isotope.metafizzy.co/)

  • Wednesday, August 24, 2016
  • by nerburish
  • Repository
  • 3 Watchers
  • 4 Stars
  • 261 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 7 % Grown

The README.md

Yii2 Isotope ListView Widget

Yii2 widget to extend the Yii2 ListView for use it as Isotope grid (http://isotope.metafizzy.co/), (*1)

Widget demo screenshot: demo, (*2)

Installation

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)

Usage

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)

Exemple

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)

The Versions

24/08 2016

dev-master

9999999-dev

ListView widget improved to use Isotope (http://isotope.metafizzy.co/)

  Sources   Download

MIT

The Requires

 

by Avatar nerburish

extension yii2 widget view dataprovider listview isotope masonry