magento中自定义模块的Ajax分页
今天,我在magento前端实现了Ajax分页。请看一看,这可能有助于你理解 块文件magento中自定义模块的Ajax分页,magento,Magento,今天,我在magento前端实现了Ajax分页。请看一看,这可能有助于你理解 块文件 class Namesapce_ModuleName_Block_Productlist extends Mage_Core_Block_Template { public function __construct() { $this->_setProductCollaction(); } private function _setProductCol
class Namesapce_ModuleName_Block_Productlist extends Mage_Core_Block_Template
{
public function __construct()
{
$this->_setProductCollaction();
}
private function _setProductCollaction()
{
/** YOUR COLLACTION **/
$collection = Mage::getModel('catalog/product')->getCollection();
$this->setCollection($collection);
}
protected function _prepareLayout()
{
parent::_prepareLayout();
$pager = $this->getLayout()->createBlock('page/html_pager', 'custom.pager');
$pager->setAvailableLimit(array(5 => 5));
$pager->setCollection($this->getCollection());
$this->setChild('pager', $pager);
$this->getCollection()->load();
return $this;
}
public function getPagerHtml()
{
return $this->getChildHtml('pager');
}
}
您的PHTML文件
<table class="data-table gapBottom14" id="order-table">
<colgroup>
<col width="23%" />
<col width="67%" />
<col width="10%" />
</colgroup>
<thead>
<tr class="first last">
<th rowspan="1"><span class="nobr"><?php echo $this->__('sku'); ?></span></th>
<th rowspan="1"><span class="nobr"><?php echo $this->__('NAME'); ?></span></th>
</tr>
</thead>
<tbody>
<?php foreach($products as $product): ?>
<tr class="first odd">
<td><?php echo $product->getSku(); ?></td>
<td class=""><?php echo $product->getName(); ?></td>
</tr>
<?php endforeach;?>
</tbody>
</table>
<?php echo $this->getPagerHtml();?>
你的问题是什么?我没有任何问题。这是对AJAX分页工作原理的解释。请在顶部发布一个问题,描述可能会用到的用例/情况/场景,如果您想解释AJAX分页工作原理,只需回答您自己的问题。@Kandarppetel请帮助我回答这个问题。你能帮我解释一下这是什么“$pager=$this->getLayout()->createBlock('page/html_pager','custom.pager');”因为它给了我无效的块类型错误@kandarppetel
jQuery(document).ready(function() {
jQuery(".pagination a").live('click', function(event) {
event.preventDefault();
page = jQuery(this).html();
updateTable(page);
});
function updateTable(pageno){
jQuery.ajax({
type:"get",
url:'<?php echo $this->getUrl('*/*/filterproduct'); ?>?p='+pageno+',
success: function(data) {
jQuery("#productlist").html(data);
}
});
}
public function filterproductAction()
{
echo
Mage::app()->getLayout()
->createBlock('modulename/productlist')->setTemplate('modulename
/productlist.phtml')->toHtml();
}