php - Magento Admin Grid Field Custom filter issue -
i have created magento admin module grid , field having custom filter.
$this->addcolumn('diff', array( 'header' =>'diff.', 'align' =>'left', 'type' => 'number', 'index' =>'diff', 'filter_condition_callback' => array($this, '_difffilter'), ));
collection having group below:
$collection->getselect()->group(array('main_table.order_id'));
custom filter function below:
protected function _difffilter($collection, $column) { if (!$value = $column->getfilter()->getvalue()) { return $this; } $_filter_data = $column->getfilter()->getvalue(); if($_filter_data["from"]!=''){ $collection->getselect()->having('round((main_table.base_cost-main_table.base_price)*100/main_table.base_cost) >= ?', $_filter_data["from"]); } if($_filter_data["to"]!=''){ $collection->getselect()->having('round((main_table.base_cost-main_table.base_price)*100/main_table.base_cost) <= ?', $_filter_data["to"]); } return $this; }
using function if load admin grid it's throwing below error: sqlstate[42s22]: column not found: 1054 unknown column 'main_table.base_cost' in 'having clause'
but grab select query $collection->getselect()
using , run mysql directly then, working fine, throwing error magento.
i did lots of research it's not working @ magento.
having
clauses used filter results of grouped query. if want filter columns in table, use where
clause:
protected function _difffilter($collection, $column) { if (!$value = $column->getfilter()->getvalue()) { return $this; } $_filter_data = $column->getfilter()->getvalue(); if($_filter_data["from"]!=''){ $collection->getselect()->where('round((main_table.base_cost-main_table.base_price)*100/main_table.base_cost) >= ?', $_filter_data["from"]); } if($_filter_data["to"]!=''){ $collection->getselect()->where('round((main_table.base_cost-main_table.base_price)*100/main_table.base_cost) <= ?', $_filter_data["to"]); } return $this; }
Comments
Post a Comment