Jquery UI sortable update single record -
i have list this:
<ul id="sortable"> <li class="ui-state-default" id="31"> list item </li> <li class="ui-state-default" id="32"> list item </li> </ul>
and in backend (cakephp) have following action:
public function ajaxupdateorder(){ $this->autorender = false; if(!empty($this->request->data)){ $meetingstable = tableregistry::get('meetings'); $meeting = $meetingstable->newentity(); $meeting->id = $this->request->data['id']; $meeting->priority = $this->request->data['priority']; $meetingstable->save($meeting); } }
i need able catch id
li
element , current possition able make request fits backend function, cannot figure out docummentation.
any or guidance appreciated.
edit
as requested in comments below:
i want fire ajax request after 1 of items changes positions. request need pass 2 variables each item has changed it's position, namely: id (from <li id="">
) , possition (new position in ul
)
you can use update
callback trigger ajax request:
$("#sortable" ).sortable({ update: function(e,ui){ $.ajax({ url:'/ajaxupdateorder', // url of service data: { id: ui.item.attr('id'), position: ui.item.index() } }); } });
Comments
Post a Comment