2012-08-14 72 views
3

我在magento后端创建网格,但分页不起作用。无论我选择每页有多少条记录,页面上始终显示所有记录。现在我有41条记录在数据库和“统计”网格上方都OK(发现页数和记录数):Magento - 网格分页

Page 1 of 3 pages | View 20 per page | Total 41 records found 

哪个文件是负责分页的? 还有另一个问题,按特定的顺序排列。例如。记录显示或者以同样的方式,我选择ASC或ID DESC顺序...

网:

public function __construct() { 
     parent::__construct(); 

     $this->setId('logger_grid'); 
     $this->setUseAjax(FALSE); 
     $this->setDefaultSort('id'); 
     $this->setDefaultDir(Varien_Data_Collection::SORT_ORDER_ASC); 
     $this->setSaveParametersInSession(TRUE); 
    } 

    public function _prepareCollection() { 
     $collection = Mage::getModel('logger/logger')->getCollection()->load(); 
     $this->setCollection($collection); 
     return parent::_prepareCollection(); 
    } 

    public function _prepareColumns() { 
     $this->addColumn('id', array(
      'header' => Mage::helper('logger')->__('ID'), 
      'sortable' => TRUE, 
      'index' => 'log_id', 
      'editable' => FALSE, 
     )); 

     $this->addColumn('interface', array(
      'header' => Mage::helper('logger')->__('Interface'), 
      'sortable' => TRUE, 
      'index' => 'interface', 
      'editable' => FALSE, 
     )); 

     $this->addColumn('type', array(
      'header' => Mage::helper('logger')->__('Type'), 
      'sortable' => TRUE, 
      'index' => 'type', 
      'editable' => FALSE, 
     )); 

     $this->addColumn('description', array(
      'header' => Mage::helper('logger')->__('Description'), 
      'sortable' => TRUE, 
      'index' => 'description', 
      'editable' => FALSE, 
     )); 

     $this->addColumn('message_data', array(
      'header' => Mage::helper('logger')->__('Message'), 
      'sortable' => TRUE, 
      'index' => 'message_data', 
      'editable' => FALSE, 
     )); 

     $this->addColumn('time', array(
      'header' => Mage::helper('logger')->__('Time'), 
      'sortable' => TRUE, 
      'index' => 'time', 
      'editable' => FALSE, 
      'type' => 'datetime', 
     )); 

     return parent::_prepareColumns(); 
    } 

    public function getRowUrl($row) { 
     return $this->getUrl('*/*/edit', array('id' => $row->getId())); 
    } 

Collection.php:

public function _construct(){ 
    $this->_init("logger/logger"); 
} 

回答

4

好的,问题解决了。一如既往只是一件小事...在_prepareCollection()函数中我用 $collection = Mage::getModel('logger/logger')->getCollection()->load();和分页没有工作,因为load()函数。

感谢回答,sparcksoft :)

+0

非常感谢,你救了我的命 – 2016-09-24 13:38:20

1

如果您创建一个自定义集合资源模型,这可能是因为您覆盖或破坏了{{_renderLimit()}}的实现,它会根据当前页面和页面大小为基础SQL查询添加限制。

// Varien_Data_Collection_Db 
protected function _renderLimit() 
{ 
    if($this->_pageSize){ 
     $this->_select->limitPage($this->getCurPage(), $this->_pageSize); 
    } 

    return $this; 
} 

你可以发布你的集合资源模型的相关部分,也许你的网格块吗?