M
M
My joy2018-12-11 13:33:43
Yii
My joy, 2018-12-11 13:33:43

Yii2 / How to pull data from filter in own widget?

Hi friends!
I'm making my own widget to use in gridview filters, can't figure out how to get preset data from 'filter'?
in GridView:

...
[
  'attribute' => 'prefix',
  'filter' => Companies::getAllAsArray('id', 'title'),
  'filterType' => '\common\widgets\Button',
  'format' => 'raw',
  'value' => function($model) {
    return '<b>' . $model->prefix . '</b>';
  },
],
...

the Button widget itself:
<?php

namespace common\widgets;

use Yii;

class Button extends \yii\base\Widget
{

  public $options;
  public $theme;
  public $model;
  public $attribute;
  public $data;
  public $value;
  public $filter;

  public function init()
  {
    parent::init();
  }

  public function setPluginOptions($options)
  {
    $this->options = $options;
  }

  public function run()
  {
    echo "
      <script>var filterButton_{$this->attribute} = true;</script>
      <a href='javascript:;' class='btn btn-default btn-block' id='filter-button-{$this->attribute}'>Все</a>
    " . print_r($this->filter, true);
  }
}

If I remove 'filterType' => '\common\widgets\Button',that I will receive normal select. And with the indication of my widget, I xs how to put this data into it.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question