I fixed the design problem by calling the class on the table... Durh :) Still have the problem with it first appearing after i click once, and it's not changeing pages visual.
Jan 27, 2016
9
Level 7
Laravel Ajax pagination
I'm following a guide on how to make the pagination called with Ajax, but i', having a little trouble 3 problems one:
- It first shows up after i click, on one of the links() in the pagination
- The pagination's links() dosn't move it's just on one.
- the style in the table are not correct at all, but im gusseing that cause it comes inside the tag I'm using to call it
Here are my code: (I'm trying to show the tasks assigned to a user, on the users page.)
The scipt on Users show page
<script>
// Ajax pagination
$(document).on('click', '.pagination a', function (e) {
e.preventDefault();
var page = ($(this).attr('href').split('page=')[1]);
getTasks(page);
});
function getTasks(page) {
console.log('Tasks page =' + page);
$.ajax({
url: '/rockcrm/public/ajax/tasks/test?page=' + page
}).done(function(data) {
$('.clients').html(data);
});
}
</script>
Tasks/test.blade.php
@foreach($tasks as $task)
<tr>
<td>
<a href="{{ route('tasks.show', $task->id)}}">
{{ $task->title }}
</a> </td>
<td>{{date('d, F Y, H:i:s', strTotime($task->created_at))}} </td>
<td>{{date('d, F Y', strTotime($task->deadline))}}({{ $task->days_until_deadline }})</td>
</tr>
@endforeach
{!! $tasks->links()!!}
Users show page
<table class="table table-hover sortable">
<h3>Open tasks ({{$user->tasksAssign->count()}})</h3>
<thead>
<thead>
<tr>
<th>Title</th>
<th>Created at</th>
<th>Deadline</th>
</tr>
</thead>
<tbody>
<tr class="clients"></tr>
</tbody>
</table>
{!! $tasks->links()!!} //This is the one im click to make the data appear
And last the route
Route::get('/ajax/tasks/test', function ()
{
$user = User::with('tasksAssign')->firstOrFail();
$tasks = $user->tasksAssign()->paginate(2);
return view('tasks.test', compact('user', 'tasks'))->render();
});
Level 6
Did you consider using datatables, they saved me a lot of time and headache.
Try this one https://github.com/yajra/laravel-datatables and here is their web site with great tutorials https://github.com/yajra/laravel-datatables
1 like
Please or to participate in this conversation.