Jairus
Jairus

Reputation: 846

Add filter property to Yii2 yii\grid\ActionColumn class

Currently there is no filter property in the Yii 2.0's actionColumn class, meaning you can not add content to the filter cell.

How can I extend the yii\grid\actionColumn class and add the filter property functionality that is in the yii\grid\column class so I can move my clear-filter button from the header to filter cell?

Gridview Filter and Header Cells

Upvotes: 2

Views: 1815

Answers (1)

BlueZed
BlueZed

Reputation: 859

In theory you can just create a new class extending the ActionColumn class like this:

namespace app\components;

use yii\grid\ActionColumn;
use yii\helpers\Html;

class MyActionColumn extends ActionColumn
{

    /**
     * @inheritdoc
     */
    protected function renderFilterCellContent()
    {
        return Html::button('Clear Filter');
    }

}

Then you can use this class in your column definition like this:

'class' => 'app\components\MyActionColumn'

which will add your button to every column where you are using this new class.

Obviously you can add a lot more functionality and customise it even further.

Hope it helps...

Upvotes: 3

Related Questions