I want to add field sort order in admin grid and in frontend part (sort by). I make module "news" and want to sort my news by title.

Please guide me how to do it

protected function _prepareCollection()
    $collection = Mage::getModel('mdnews/news')->getCollection();
    return parent::_prepareCollection();
protected function _prepareColumns()
    $helper = Mage::helper('mdnews');

    $this->addColumn('news_id', array(
    'header' => $helper->__('News ID'),
    'index' => 'news_id',
    'width' => '100px',

   $this->addColumn('title', array(
    'header' => $helper->__('Title'),
    'index' => 'title',
    'type' => 'text',

   $this->addColumn('category', array(
    'header' => $helper->__('Category'),
    'index' => 'category_id',
    'options' => $helper->getCategoriesList(),
    'type'  => 'options',
    'width' => '150px',

   $this->addColumn('created', array(
    'header' => $helper->__('Created'),
    'index' => 'created',
    'type' => 'date',

   return parent::_prepareColumns();
  • kindly add your grid code for better understanding the question – Qaisar Satti Jan 27 '16 at 11:11
  • sorry, added my code – O.Petrov Jan 27 '16 at 11:15

add these two in _construct this will do in admin..

public function __construct()
$this->setDefaultSort('title'); //default field to sort
$this->setDefaultDir('ASC'); //sort by ASC ot DESC


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.