On Thu, Mar 17, 2011 at 6:48 AM, Ryan <[email protected]> wrote: > I'm trying to display a list of items from the database and let the > user drag them around to sort them however they like. Each time they > drag something, a function should fire that loops through all of the > rows and saves the sort order to the database so that the next time > the user loads that page, everything is sorted like it was when they > left. I don't know much at all about AJAX/javascript so have just been > looking for tutorials/code samples to do this....I found something > that uses CakePHP's built in AJAX sortable. I've got the drag & drop > working, but it's not firing the function to go to the database. > > Please help!! > > > VIEW: > > <div id="items"> > <?php > foreach ($items as $item): ?> > > <div id="item_<?php echo $item['Item']['id']; ?>" > class="item"> > <?php echo $item['Item']['name'];?> > </div> > > <?php endforeach; ?> > </div> > > > <?php echo $ajax->sortable('items', array( > 'tag' => 'div', > 'only' => 'item', > 'hoverclass' => 'selected', > 'url' => array('controller' => 'items', 'action' => 'order') > )); > ?> > > > > CONTROLLER: > > function order() { > if ($this->RequestHandler->isAjax()) { > $ids= $this->params['form']['items']; > $i = 1; > foreach ($ids as $id) { > $this->Item->id = $id; > $this->Item->saveField('sort_order', $i++); > } > $this->autoRender = false; > } > } > > > > > > I'm importing the 'Javascript', 'Ajax' Helpers in app_controller.php. > I also tried 'onUpdate' => array('controller' => 'items', 'action' => > 'order') instead of 'url' => array('controller' => 'items', 'action' > => 'order')....but that doesn't work either. > > Any help would be VERY much appreciated. Thank you!!
I can't tell you anything about Cake's sort but I've pasted a quick run-down on how I deal with this using JQuery here: http://pastebin.com/5dU4D6Pt In the controller, use $this->log($this->params['url']) to see how things initially come in. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php
