Back to Top

How Filter Work In Rendered Column In Grid Magento 2

Updated 16 July 2021

How Filter Work In Rendered Column In Grid Magento 2 : Sometime we need to render a column to show meaningful data. so when we render a column in default magento 2 grid. then its very challenging to do filter on that column.
so here i am going to explain how you can filter rendered column.

1 => in your grid file.

protected function _prepareColumns()
{
    $this->addColumn('custom_template_id', 
    [
        'header' => __('Template Name'),
        'index' => 'custom_template_id'
        'renderer'  =>'Webkul\CustomTest\Block\Adminhtml\Template\Edit\Tab\Renderer\TemplateName','filter_condition_callback' => [$this, '_filterCollection'],
    ]);
}

protected function _filterCollection($collection, $column)
{
    $value = trim($column->getFilter()->getValue());

    $this->getCollection()->getSelect()->where(
        // do filter 
    );

    return $this;
}

using filter_condition_callback you can filter rendered column.

Hope so it will help.

Searching for an experienced
Magento 2 Company ?
Find out More
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home