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()));
    }

Collection.php:

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

4 に答える 4

5

わかりました、問題は解決しました。いつものように、ちょっとしたこと..._prepareCollection()私が使用 $collection = Mage::getModel('logger/logger')->getCollection()->load();した機能では、機能のためにページネーションが機能しませんでしたload()

お返事ありがとうございます、sparksoft :)

于 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 に答える