View code:
<div id="tabs">
<div class="col-md-12" id="current">
@include('cms.public.views.partials._messages')
<div id="table1">
<table class="table">
<thead style="color:white">
<tr>
<th><a href="{{route('admin.projects.order', ['field' => 'id','order' => 'asc'])}}"><span class="glyphicon glyphicon-arrow-up" id="orderByIdAsc"></span></a>ID<a href="{{route('admin.projects.order', ['field' => 'id','order' => 'desc'])}}"><span class="glyphicon glyphicon-arrow-down" id="orderByIdDesc"></span></a></th>
<th><a href="{{route('admin.projects.order', ['field' => 'slug','order' => 'asc'])}}"><span class="glyphicon glyphicon-arrow-up" id="orderBySlugAsc"></span></a>SLUG<a href="{{route('admin.projects.order',['field' => 'slug','order' => 'desc'])}}"><span class="glyphicon glyphicon-arrow-down" id="orderBySlugDown"></span></a></th>
<th><a href="{{route('admin.projects.order', ['field' => 'order','order' => 'asc'])}}"><span class="glyphicon glyphicon-arrow-up" id="orderByOrderAsc"></span></a>ORDER<a href="{{route('admin.projects.order', ['field' => 'order','order' => 'desc'])}}"><span class="glyphicon glyphicon-arrow-down" id="orderByOrderDesc"></span></a></th>
<th><a href="{{route('admin.projects.order', ['field' => 'public','order' => 'asc'])}}"><span class="glyphicon glyphicon-arrow-up" id="orderByPublicAsc"></span></a>PUBLIC<a href="{{route('admin.projects.order', ['field' => 'public','order' => 'desc'])}}"><span class="glyphicon glyphicon-arrow-down" id="orderByPublicDesc"></span></a></th>
<th><span class="glyphicon glyphicon-cog"></span></th>
</tr>
</thead>
<tbody style="color:white">
@foreach ($projects as $key => $project)
<tr>
<td>{{$project->id}}</td>
<td>{{$project->slug}}</td>
<td>{{$project->order}}</td>
<td>{{$project->public}}</td>
<td><a href="{{ route('admin.projects.show', $project->id)}}" class="btn btn-info btn-sm">View</a> <a href="{{ route('admin.project.edit', $project->id)}}" class="btn btn-success btn-sm">Edit</a></td>
</tr>
@endforeach
</tbody>
</table>
<br><br>
</div>
</div>
</div>
Jquery Code:
$("#tabs").tabs();
$("tbody").sortable({
items: "> tr",
appendTo: "parent",
helper: "clone"
}).disableSelection();
$("#tabs ul li a").droppable({
hoverClass: "drophover",
tolerance: "pointer",
drop: function(e, ui) {
var tabdiv = $(this).attr("href");
$(tabdiv + " table tr:last").after("<tr>" + ui.draggable.html() + "</tr>");
ui.draggable.remove();
}
});
Could someone give me an example of how to automatically update the data in the database, when moving a row?
Update
I will be much more detailed so that you understand me better and can help me.
The view is sorted by the 'order' field, that is, the data is displayed as follows:
id - pepito- 29 - public
id - slug - 28 - public
id - slug - 27 - public
id - slug - 26 - public
id - slug - 25 - public
id - slug - 24 - public
y así hasta el
id - ultimopepito- 1 - public
If I drag, for example, the one with the field 'order' = a 1 above the whole view looks like this:
id - ultimopepito- 1 - public
id - pepito- 29 - public, etc.
The idea would be to update the data when doing the 'drop' and it looks like this:
id - ultimopepito - 29 - public
id - pepito - 28 - public
For this, when doing the 'drop' you have to update the data automatically.
I think that could be done like this: Take the order of the drag and take the order of the drop. If the movement is up, I would subtract one from the ones below the drop and vice versa, the problem is that I do not have the knowledge to do this.