Ajax Pagination append the element instead of updating id

China☆狼群 提交于 2019-12-24 00:59:53

问题


I am working on Cakephp application. What I want here is to create facebook style pagination. Still I have done with Ajax pagination on simple sorting. Now my logic with this I will create button of next. and render element. Cakephp will itself manage pagination. But my issue is its rendering my view to particular div(ID) that it ask me during 'update'. My style of dom is...

<div class="fb_style" id='1'></div>
<div class="fb_style" id='2'></div>
<div class="fb_style" id='3'></div>
<div class="fb_style" id='4'></div>
<div class="fb_style" id='5'></div>
<div class="fb_style" id='6'></div>
<div id='more button'>MORE BUTTON(ACTUALLY PAGINATOR NEXT LINK)</div>

I want to render the div next to id=6 or I can say next to .fb_style:last My pagination sample code...I simple wish to append to particular dom element.

$this->Paginator->_ajaxHelperClass = "Ajax";
$this->Paginator->Ajax = $this->Ajax;
$this->Paginator->options(array('update' => 'listID',
    'url' => array('controller' => 'poets', 'action' => 'index', $separator),
    'indicator' => 'loaderID'));

If I do it with Jquery means to write function than its quite clumpsy means I have to send total records, than validate the limit manually, on view check if total records are equal or more so I move with above logic let me know if it correct...or any other solution or guide line with it.


回答1:


I used Infinite scrolling JQuery plugin and it is just working fine. This jquery plugin will give you custom built-in events that you can use to send Ajax request to your controller's method. Also if it will be working then you can change it css to looks like facebook infinite scrolling functionality.

Here is another post that will help you how to use it with CakePHP.




回答2:


Use the twitter style of pagination, although your ordering ASC, while facebook and twitter order DESC, it would still apply.

Send the min_id form the first results as param, and use that in your conditions in index() so the next request would get the next block of results.

This is safer then getting page 2 as new records might have been added in the meanwhile so you would be missing records or have duplicates (only applies when you would change to order DESC, for ASC ordering it would be safe to use page 2)

'update' => 'listID'

should be

'update' => '#listID'


来源:https://stackoverflow.com/questions/11564995/ajax-pagination-append-the-element-instead-of-updating-id

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!