We can overwrite _setCollectionOrder() in Adminhtml Grid.php file.

// Developed Example

protected function _setCollectionOrder($column)
{
$collection = $this->getCollection();
$severity = ($this->severity) ? $this->severity : ‘1,2,3,4’;
$collection->getSelect()->where(“is_remove=0 AND (from_typo = ‘0’) OR (from_typo != 0 AND severity IN (“.$severity.”)) “);

if ($collection) {
$columnIndex = $column->getFilterIndex() ? $column->getFilterIndex() : $column->getIndex();
$collection->getSelect()->order($columnIndex.’ ‘.strtoupper($column->getDir()));
}
return $this;
}

// Another example

protected function _setCollectionOrder($column)
{
$collection = $this->getCollection();
if ($collection) {
$columnIndex = $column->getFilterIndex() ? $column->getFilterIndex() : $column->getIndex();
if($columnIndex == ‘pages_with_number_of_views.order_count’)
{
$columnIndex = ‘order_count’;
$collection->getSelect()->order($columnIndex.’ ‘.strtoupper($column->getDir()));
}
if($columnIndex == ‘total_sales’){
$collection->getSelect()->order($columnIndex.’ ‘.strtoupper($column->getDir()));
}
else{
$collection->setOrder($columnIndex, strtoupper($column->getDir()));
}
}
return $this;
}

Advertisements