2017 © Pedro Pelรกez
 

yii2-extension yii2-widget-next-button

Widget render wrap container for a list with next button

image

diiimonn/yii2-widget-next-button

Widget render wrap container for a list with next button

  • Monday, February 23, 2015
  • by diiimonn
  • Repository
  • 1 Watchers
  • 0 Stars
  • 33 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

yii2-widget-next-button

Widget render wrap container for a list with next button., (*1)

Installation

To install with composer:, (*2)

$ php composer.phar require diiimonn/yii2-widget-next-button "dev-master"

or add, (*3)

"diiimonn/yii2-widget-next-button": "dev-master"

to the require section of your composer.json file., (*4)

Usage

controller:

...
use yii\data\Pagination;
...

class SiteController extends Controller
{
    ...
    public function actionIndex($id)
    {
        ...
        $query = MyModel::find();

        $queryCount = clone $query;

        $pagination = new Pagination([
            'totalCount' => $queryCount->count(),
            'pageSize' => 10,
            'page' => 0,
        ]);

        $isNext = $pagination->getPageCount() > 1;

        $query->offset($pagination->offset);
        $query->limit($pagination->limit);
        $models = $query->all();

        ...

        return $this->render('index', [
            ...
            'models' => $models,
            'isNext' => $isNext,
        ]);
    }

    ...

    public function actionNext($id, $page = 0)
    {
        Yii::$app->response->format = 'json';

        $json = new \stdClass();

        $query = MyModel::find();

        $queryCount = clone $query;

        $pagination = new Pagination([
            'totalCount' => $queryCount->count(),
            'pageSize' => 10,
            'page' => $page,
        ]);

        $nextPage = $page + 1;

        $json->page = $pagination->getPageCount() > $nextPage ? $nextPage : 0;

        $query->offset($pagination->offset);
        $query->limit($pagination->limit);
        $models = $query->all();

        ...

        $json->html = $this->renderPartial('_items', [
            ...
            'models' => $models,
        ]);

        return $json;
    }

    ...
}

structure views:

โ”œโ”€โ”€ site
โ”‚ย ย  โ”œโ”€โ”€ index.php
โ”‚ย ย  โ”œโ”€โ”€ _items.php
โ”‚ย ย  โ”œโ”€โ”€ ...

view index.php

...
use diiimonn\widgets\NextButton;
use yii\helpers\Url;

...

 Yii::t('app', 'Show next ...'),
    'buttonOptions' => [/* button tag options */],
    'isNext' => $isNext,
    'scriptOptions' => [
        'ajax' => [
            'url' => Url::toRoute(['next', /* other params */]), // Url for ajax request to actionNext in SiteController. Required parameter
        ],
    ],
    'options' => [/* widget tag options */],
    'containerOptions' => [/* container tag for items options */],
    'buttonContainerOptions' => [],
    'buttonBlockOptions' => [], // for example ['class' => 'row']
    'buttonWrapOptions' => [], // for example ['class' => 'col-md-6 col-md-offset-3']
]) ?>

= $this->render('_items', [
    ...
    'models' => $models,
]) ?>


...

The Versions

23/02 2015

dev-master

9999999-dev https://github.com/diiimonn/yii2-widget-next-button

Widget render wrap container for a list with next button

  Sources   Download

by Dmitriy Gavrilenko

extension yii2 jquery ajax widget next button

23/02 2015

v1.0.0

1.0.0.0 https://github.com/diiimonn/yii2-widget-next-button

Widget render wrap container for a list with next button

  Sources   Download

by Dmitriy Gavrilenko

extension yii2 jquery ajax widget next button