3

我在 magento 后端创建了网格,但分页不起作用。无论我选择每页有多少条记录,它们总是在页面上可见。现在我在数据库中有 41 条记录,并且网格上方的“统计信息”正常(找到的页数和记录数):

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

哪个文件负责分页?某些列的顺序还有另一个问题。例如。记录的显示方式与我按 ID 选择 ASC 或 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()));
    }

集合.php:

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

4 回答 4

5

好的,问题解决了。一如既往只是一件小事......在_prepareCollection()我使用的功能中 $collection = Mage::getModel('logger/logger')->getCollection()->load();,分页由于load()功能而不起作用。

感谢您的回复,sparcksoft :)

于 2012-08-20T09:43:48.200 回答
1

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

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

    return $this;
}

你能从你的收藏资源模型和你的网格块中发布相关部分吗?

于 2012-08-14T16:12:36.270 回答
0

你可以使用这个:

protected function _prepareCollection()
{
    $collection = Mage::getModel('vendor/model')->getCollection();
    $this->setCollection($collection);
    //
    return Mage_Adminhtml_Block_Widget_Grid::_prepareCollection();
}

在这种情况下,您可以访问您的自定义模型并使用分页显示

于 2020-04-14T10:33:58.400 回答
-3

要解决此问题,您需要编辑您的核心文件之一,请点击以下链接:

https://raisereview.com/wrong-grid-count-and-pagination-issue-in-magento-admin-grid/

于 2014-10-30T11:49:23.577 回答