![]() |
jQuery Sortable save new order to database - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: jQuery Sortable save new order to database (/showthread.php?tid=59816) |
jQuery Sortable save new order to database - El Forum - 11-23-2013 [eluser]ZioN[/eluser] I've been looking for quite some time for a way to save the new 'order'. I want to let the users of my system re-order a list. But I cannot get it to save it to the database. View: Code: $( document ).ready(function() { Controller: Code: function save_order() It seems the ID is not coming through: UPDATE `pages` SET `order` = 1 WHERE `id` IS NULL jQuery Sortable save new order to database - El Forum - 11-23-2013 [eluser]CroNiX[/eluser] Try Code: function save_order() jQuery Sortable save new order to database - El Forum - 11-23-2013 [eluser]CroNiX[/eluser] If that doesn't work try doing a Code: print_r($items); die(); Also, in your ajax call, I think you should only be sending Code: data: { jQuery Sortable save new order to database - El Forum - 11-24-2013 [eluser]ZioN[/eluser] Hi CroNiX, Thank you for your reply. I'm fairly new to AJAX but i'm trying ![]() I'm getting an "Message: Invalid argument supplied for foreach()" print_r($items); does not return anything. var_dump($_POST); returns: Code: array(1) { ["items"]=> string(26) "item[]=1&item;[]=3&item;[]=2" } jQuery Sortable save new order to database - El Forum - 11-25-2013 [eluser]CroNiX[/eluser] What does your UL HTML look like? Do you have id's set for each LI similar to below? The UL Code: <ul id="sort"> The sortable js Code: $('#sort').sortable({ The receiving controller Code: function the_url_to_save() jQuery Sortable save new order to database - El Forum - 11-25-2013 [eluser]ZioN[/eluser] Code: <ul id="sort"> With your code I see Code: ["1", "3", "2"] in my console. jQuery Sortable save new order to database - El Forum - 11-25-2013 [eluser]CroNiX[/eluser] That seems about right. That would mean the order of id 1 is first, id 3 is second, and id 2 is third. So now in the the_url_to_save() method, Code: function the_url_to_save() You'd actually do that db stuff in a model and return the result to the controller, but this should now work as is. jQuery Sortable save new order to database - El Forum - 11-25-2013 [eluser]skunkbad[/eluser] I don't know if it would be of any help, but Community Auth has an example of a draggable/droppable/sortable file uploader. It couldn't hurt to look at it. jQuery Sortable save new order to database - El Forum - 11-26-2013 [eluser]ZioN[/eluser] CroNiX, Thank you so much. It did the trick. I will go over the code and try to figure out what it's doing. And clean the code (doing the db stuff in the model). |