First of all, thanks for Camille Lach for his hint, I managed to do it
Here is my code, maybe someone wull will make use for it
created a function in my controller and loaded the model into it
function sort_items() { $this->load->model("admin/pages_model"); $this->pages_model->sort_insert(); }
model
function sort_insert() { foreach($this->input->post("sort") as $p => $id) { $this->db->query(" UPDATE c_pages SET sort = ".$p." WHERE pid = ".$id." "); } }
$ p vaiable is a short position, and id is the menu id
and jquery
$( "#sortable" ).sortable({ placeholder: "ui-state-highlight", opacity: 0.6, update: function(event, ui) { var info = $(this).sortable("serialize"); $.ajax({ type: "POST", url: "http://localhost/frame/admin/pages/sort_items", data: info, context: document.body, success: function(){
I passed the URL of my controller function where my update model is loaded
and view file
<?php if($rows) { ?> <ul id="sortable"> <?php foreach ($rows as $r) { echo ' <li id="sort_'.$r->pid.'" class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-ns"></span> ' . $r->page_name . ' </li>'; } ?> </ul> <?php } else { echo "There are no pages created yet"; } ?>
And thanks again for your hint Camil Lach
Side
source share