jquery - cakephp 2x + ajax pagination + prototype js -
i want create add/edit/delete , active/deactive (with ajax) in listing page. here have uploaded demo http://mehul.pw/cp/categories/index right pagination working fine. when change status , use pagination not working. trying solve 3hr here have mentioned below code
controller code below:
public $helpers = array('js' => array('prototype')); public $components = array(); public function beforefilter() { parent::beforefilter(); } public $paginate = array( 'limit' => 1, 'order' => array( 'category.category_id' => 'asc' ) ); public function index() { $data = $this->paginate('category'); $this->set('categories',$data); } public function update($field,$value,$id = null,$pageno,$sortkey,$sortdir) { if (!$id) { $this->session->setflash(__('invalid id event', true)); $this->redirect(array('action'=>'index')); } $this->category->id = $id; $this->request->data['category'][$field] = $value; if($this->category->save($this->request->data)) { $this->redirect(array('action'=>'index', 'page' => $pageno, 'sort' => $sortkey, 'direction' => $sortdir)); }else{ $this->redirect(array('action'=>'index', 'page' => $pageno, 'sort' => $sortkey, 'direction' => $sortdir)); } } }
now in index file active/deactive link have used this
<?php if($post['category']['is_active'] == 'y'){ echo $this->js->link( 'active', array('action' => 'update','is_active','n', $post['category']['category_id'],$this->paginator->current(),$this->paginator->sortkey(),$this->paginator->sortdir()), array('async' => false,'update' => 'content')); }else{ echo $this->js->link( 'deactive', array('action' => 'update','is_active','y', $post['category']['category_id'],$this->paginator->current(),$this->paginator->sortkey(),$this->paginator->sortdir()), array('async' => false,'update' => 'content')); } ?>
can tell me how can solve issue ? in advance.
here have tried use ajax helper dame issue here belo mentioned fill view code
<?php // pr($this->paginator->options); $this->paginator->options(array( 'update' => '#content', 'evalscripts' => true, 'before' => $this->js->get('#busy-indicator')->effect('fadein', array('buffer' => false)), 'complete' => $this->js->get('#busy-indicator')->effect('fadeout', array('buffer' => false)), )); ?> <h1>categories list</h1> <?php //echo $this->html->link('add post',array('controller' => 'categories', 'action' => 'add')); ?> <?php echo $this->html->link('add category',array('controller'=>'categories','action'=>'add'),array("escape" => false,'class'=>'stdbtn btn_orange', "title" => "add category", "onclick" => "modalbox.show(this.href, {title: this.title, width: 700}); return false;")); ?> <table> <?php //echo $this->html->tableheaders(array('date','title','active'),array('class' => 'status'),array('class' => 'product_table'));?> <tr> <th><?php echo $this->paginator->sort('category_id', '<em>category id</em>', array('escape' => false)); ?></th> <th><?php echo $this->paginator->sort('category_name', '<em>name</em>', array('escape' => false)); ?></th> <th>description</th> <th>status</th> <th>action</th> </tr> <!-- here loop through our $posts array, printing out post info --> <?php foreach ($categories $post): ?> <tr> <td><?php echo $post['category']['category_id']; ?></td> <td> <?php echo $this->html->link($post['category']['category_name'],array('controller' => 'categories', 'action' => 'view', $post['category']['category_id'])); ?> </td> <td><?php echo $post['category']['description']; ?></td> <td> <?php if($post['category']['is_active'] == 'y'){ echo $this->js->link( 'active', array('action' => 'update','is_active','n', $post['category']['category_id'],$this->paginator->current(),$this->paginator->sortkey(),$this->paginator->sortdir()), array('async' => false,'update' => 'content')); }else{ echo $this->js->link( 'deactive', array('action' => 'update','is_active','y', $post['category']['category_id'],$this->paginator->current(),$this->paginator->sortkey(),$this->paginator->sortdir()), array('async' => false,'update' => 'content')); } ?> </td> <td> <?php echo $this->form->postlink( 'delete', array('action' => 'delete', $post['category']['category_id']), array('confirm' => 'are sure?')); ?> <?php echo $this->html->link('edit', array('action' => 'edit', $post['category']['category_id'])); ?> </td> </tr> <?php endforeach; ?> <tr> <td colspan="4" align="right"> <?php echo $this->paginator->first('< first '); echo $this->paginator->prev(' << ' . __('previous '), array(), null, array('class' => 'prev disabled')); echo $this->paginator->numbers(); echo $this->paginator->next( __(' next').' >> ' , array(), null, array('class' => 'next disabled')); echo $this->paginator->last(' last > '); //echo $this->paginator->counter('page {:page} of {:pages}, showing {:current} records out of{:count} total, starting on record {:start}, ending on {:end}'); ?> <?php echo $this->html->image('indicator.gif', array('id' => 'busy-indicator')); ?> </td> </tr> <?php unset($post); ?> </table> <?php echo $this->js->writebuffer(); ?>
===================== layout code ==============
<?php /** * * php 5 * * cakephp(tm) : rapid development framework (http://cakephp.org) * copyright (c) cake software foundation, inc. (http://cakefoundation.org) * * licensed under mit license * full copyright , license information, please see license.txt * redistributions of files must retain above copyright notice. * * @copyright copyright (c) cake software foundation, inc. (http://cakefoundation.org) * @link http://cakephp.org cakephp(tm) project * @package app.view.layouts * @since cakephp(tm) v 0.10.0.1076 * @license http://www.opensource.org/licenses/mit-license.php mit license */ $cakedescription = __d('cake_dev', 'cakephp: rapid development php framework'); ?> <!doctype html> <html> <head> <?php echo $this->html->charset(); ?> <title> <?php echo $cakedescription ?>: <?php echo $title_for_layout; ?> </title> <?php echo $this->html->meta('icon'); echo $this->html->css('cake.generic'); echo $this->fetch('meta'); echo $this->fetch('css'); echo $this->fetch('script'); ?> <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/prototype/1.7.0.0/prototype.js" type="text/javascript" charset="utf-8"></script> <script src="https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/scriptaculous.js?load=effects" type="text/javascript" charset="utf-8"></script> <?php echo $this->html->script('modalbox.js'); echo $this->html->css('modalbox.css'); ?> </head> <body> <div id="container"> <div id="header"> <h1><?php echo $this->html->link($cakedescription, 'http://cakephp.org'); ?></h1> </div> <div id="content"> <?php echo $this->session->flash(); ?> <?php echo $this->fetch('content'); ?> <?php echo $this->js->writebuffer(); ?> </div> <div id="footer"> <?php echo $this->html->link( $this->html->image('cake.power.gif', array('alt' => $cakedescription, 'border' => '0')), 'http://www.cakephp.org/', array('target' => '_blank', 'escape' => false) ); ?> </div> </div> <?php echo $this->element('sql_dump'); ?> </body> </html>
add <?php echo $this->js->writebuffer(); ?>
before closing <div id='content'>
i think pagination links aren't updating here once if fire ajax call content updating pagination links , related script pagination links aren't updating here,
i.e.
$("link-907864750").observe("click", function (event) {event.stop(); var jsrequest = new ajax.updater("content", "/cp/categories/index/sort:category_name/direction:asc", {evalscripts:true, oncomplete:function (transport) {$("busy-indicator").fade({buffer:false});}, oncreate:function (transport) {$("busy-indicator").appear({buffer:false});}});});
$("link-907864750")
link having @ first time later when click on 'deactive' or 'active' isn't updating script/ not generating script pagination links there.
note: $("#link-907864750")
example here, cake generate random ids pagination links.
@admin
ReplyDeleteWe provide all the requirements around the patients to give friendly involvement with divine and relaxed circumstances. Book an appointment and visit our clinic for our effective doctor’s experiences
Regards,
Dentist In Dracut, MA