Welcome Guest, Not a member yet? Register   Sign In
jQuery Sortable save new order to database
#1

[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() {
    $( "#sortable" ).sortable({

      placeholder: "ui-state-highlight",
            update: function(event, ui){
     data: $(this).sortable("serialize"),

            $.ajax({
                url: "/ci/acp/save_order",
                type: 'POST',
                data: {
                    'order': $( "#sortable" ).sortable('toArray'),
                },
                success: function (data) {
                    $("#test").html(data);
                }

            });
                      
            }
                
        });

    $( "#sortable" ).disableSelection();
});


echo '<li id="item-'.$row-&gt;id .'" class="ui-state-default">';

Controller:

Code:
function save_order()
    {    
  $items = $this->input->post('item');
  $total_items = count($this->input->post('item'));
    for($item = 0; $item < $total_items; $item++ )
    {

            $data = array(
                'id' => $items[$item],
               'order' => $item+1
            );

             $this->db->where('id', $data['id']);

   $this->db->update('pages', array('order' => $data['order']));
   echo $this->db->last_query();
}
}

It seems the ID is not coming through:
UPDATE `pages` SET `order` = 1 WHERE `id` IS NULL


Messages In This Thread
jQuery Sortable save new order to database - by El Forum - 11-23-2013, 11:42 AM
jQuery Sortable save new order to database - by El Forum - 11-23-2013, 01:37 PM
jQuery Sortable save new order to database - by El Forum - 11-23-2013, 01:41 PM
jQuery Sortable save new order to database - by El Forum - 11-24-2013, 12:25 PM
jQuery Sortable save new order to database - by El Forum - 11-25-2013, 10:58 AM
jQuery Sortable save new order to database - by El Forum - 11-25-2013, 01:20 PM
jQuery Sortable save new order to database - by El Forum - 11-25-2013, 01:27 PM
jQuery Sortable save new order to database - by El Forum - 11-25-2013, 03:22 PM
jQuery Sortable save new order to database - by El Forum - 11-26-2013, 12:47 AM



Theme © iAndrew 2016 - Forum software by © MyBB