I am using join collection of my custom table value with product collection in my magento store admin product grid.the problem is that i can't filter or sort that custom column with already inbuilt grid sorting and filtering functionality..i am retrieving custom value from renderer in grid..i have tried almost all things from google but still i am not able to get proper solution for that.i have also used filter_condition_callback in _prepareColumns() method of my column but it didnt make sense.so any help would be great.
Thanks
I normally use an observer to add a column to the grid. See this page (german language) how to do this.
Also the full module of this tutorial is available on GitHub.
But to help you, a bit of source code would be fine. Which custom column would you like to filter? Which values can it have?
I did it like this (in file Observer.php)
$grid->addColumnAfter(
'custom_column_code', // replace by your column code
array(
'header' => 'Label of your column',
'index' => 'custom_column_code', // replace by your column code
'type' => 'options',
'renderer' => 'YourCompany_YourModule_YourRenderer',
'filter_condition_callback' => array($this, '_filterHasMyCustomConditionCallback')
'options' => array( //these are your filter options
'1' => 'Yes',
'0' => 'No'
),
),
'name'
);
and then also in Observer.php
public function _filterHasMyCustomConditionCallback($collection, $column)
{
$value = $column->getFilter()->getValue();
if ($value == '0')
{
// join custom_column LEFT (inner join fails on NULL values) and filter by NULL
$collection->addAttributeToFilter('custom_column_code', array(['null' => true]), 'left');
}
else
{
// filter all by NOT NULL
$collection->addFieldToFilter('custom_column_code', ['notnull' => true]);
}
return $this;
}