Request Quote

How Filter Work In Rendered Column In Grid Magento 2

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.

. . .

Comment

Add Your Comment

Be the first to comment.

css.php