M
M
Maybe_V2016-07-22 17:21:55
PHP
Maybe_V, 2016-07-22 17:21:55

How to make pagination in Magento html table?

I am doing pagination for html tables according to this guide: This is
how my block looks likeapp/code/local/Developer/Vendor/Block/Customer.php

<?php


class VitaliyDev_Vendor_Block_Customer extends Mage_Core_Block_Template
{
    public function _construct()
    {
        parent::_construct();
        $collectionProducts = Mage::getModel('catalog/product')
            ->getCollection()
            ->addAttributeToSelect(array(
                'name',
                'price',
                'owner_id',
            ))
            ->addAttributeToFilter('owner_id', array(
                'id' => Mage::getSingleton('customer/session')->getCustomer()->getId(),
            ));
        $this->setCollection($collectionProducts);
    }

    protected function _prepareLayout()
    {
        parent::_prepareLayout();

        $pager = $this->getLayout()->createBlock('page/html_pager', 'custom.pager');
        $pager->setCollection($this->getCollection());
        $this->setChild('pager', $pager);
        $this->getCollection()->load();
        return $this;
    }

    public function getPagerHtml()
    {
        return $this->getChildChildHtml('pager');
    }
}

My layout
app/design/frontend/rwd/default/layout/developer_vendor.xml

<developervendor_customer_index>
        <update handle="customer_account"/>
            <reference name="content">
                <block
                        type="developervendor/customer"
                        name="index.content"
                        template="developervendor_vendor/customer/index.phtml"
                />
            </reference>
    </developervendor_customer_index>

app/design/frontend/rwd/default/template/developer_vendor/customer/index.phtml

<div class="title_customer_products">
    <?php echo $this->__('Your products')?>
</div>
<?php $collection = $this->getCollection(); ?>
<?php echo $this->getPagerHtml() ?>
<table class="customer-products data-table">
    <thead>
        <th><?php echo $this->__('Id Product')?></th>
        <th><?php echo $this->__('Name Product')?></th>
        <th><?php echo $this->__('Price Product')?></th>
    </thead>
    <tbody>
        <?php foreach ( $this->getCollection() as $product):?>
        <tr>
            <td><?php echo $product->getId()?></td>
            <td><?php echo $product->getName()?></td>
            <td><?php echo $product->getPrice()?></td>
        </tr>
        <?php endforeach;?>
    </tbody>
</table>
<?php echo $this->getPagerHtml() ?>

<form action="<?php echo Mage::getUrl('*/customer/add')?>">
    <button class="add_product_button button" type="submit">add product</button>
</form>

There is no result ( Pagination does not appear !
What am I doing wrong ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
imdeveloper, 2016-08-01
@link_web

It looks like you messed up with the class name

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question