[eluser]boldyellow[/eluser]
I'm also wrestling with sortable list items (big surprise, I'm a designer who's not JS saavy and still learning CI).
And yet... it kinda works: list items drag and the array is echoed in the #info box.
But the row order does not update in the database. And it doesn't seem very MVC (it calls on a separate PHP file).
It's not gonna be a long list, so performance is not huge concern.
Database: gallery_names
Code:
| id | name | order |
View
In the view header:
Code:
$(document).ready(function() {
$("#sortable-list").sortable({
update : function () {
var order = $('#sortable-list').sortable('serialize');
$("#info").load("http://localhost/ci/process-sortable.php?"+order);
}
});
});
And in the view body:
Code:
<div id="info">Waiting...</div>
<ul id="sortable-list">
<li id="listfield_01">Gallery 1</li>
<li id="listfield_02">Gallery 2</li>
<li id="listfield_03">Gallery 3</li>
</ul>
Separate PHP File: process-sortable.php
Code:
foreach ($_GET['listfield'] as $order => $item) :
$sql[] = "UPDATE `gallery_names` SET `order` = $order WHERE `id` = $item";
endforeach;
echo '<pre>';
print_r ($sql);
echo '</pre>';
Taking a stab here...
When the header script posts, it should go to the controller which gets the $_POST.
The controller loads a model with a variation of the process-sortable code and updates the db(?)
Thanks for any guidance!