Answer the question
In order to leave comments, you need to log in
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');
}
}
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>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question