Support the ongoing development of Laravel.io →
Views Blade Installation

I am trying to implement pagination with ajax + laravel pagination.

UserRegistrationQueue.php controller has

$users = User::GetPendingUsers()->paginate(25);
        $roles = Role::all()->lists('display_name', 'id');
        if($request->ajax()) {
            return view('userRegistrationQueue.showAjax', compact(['users', 'roles']));
        }

        return view('userRegistrationQueue.show', compact(['users', 'roles']));

*javascript ajax request looks like this *

$('.content').on('click','.pagination a',function (event) {
    event.preventDefault();
    if ( $(this).attr('href') != '#' ) {
        $("html, body").animate({ scrollTop: 0 }, "fast");
        $('#pag').load($(this).attr('href'));
    }
});

view which is shown

@extends('layout.admin')
@section('content')
    <input type="hidden" name="_token" value="{{ csrf_token() }}" />
    <div class="row">
        <div class="col-sm-12">
            <h2 class="page-header">Users request</h2>
        </div>
    </div>
    <div class="row" >
        <div class="col-sm-12">
            <h2>Role assigning</h2>
            <div class="table-responsive" >
                <table class="table table-bordered table-hover">
                    <thead>
                    <tr>
                        <th>Id</th>
                        <th>Name</th>
                        <th>Email</th>
                        <th>Role</th>
                        <th>Status</th>
                    </tr>
                    </thead>
                    <tbody id="pag">
                    @include('userRegistrationQueue.showAjax')
                    </tbody>
                </table>

            </div>
        </div>
    </div>
@endsection

view which is returned on ajax request

@foreach($users as $user)
    <tr>
        <td> {{$user->id}} </td>
        <td> {{$user->name}} </td>
        <td> {{$user->email}} </td>
        <td> {!! Form::select('role', $roles) !!} </td>
        <td class="center-text">
            <div class="btn-group inline">
                <a href="javascript:void(0)" class="btn btn-success btn-xs" data-id="{{$user->id}}" id="acceptUserAdmin" onclick="acceptUser({{$user->id}})">accept</a>
                <a href="javascript:void(0)" class="btn btn-xs btn-danger" data-id="{{$user->id}}" id="declineUserAdmin" onclick="declineUser({{$user->id}})">decline</a>
            </div>
        </td>
    </tr>

@endforeach

{{--renders bootstrap pagination--}}

{!! $users->render() !!} **DOES NOT WORK**

what I mean by saying "does not work" is that it is not rendered current pagination state. pagination example here on image I clicked on the second page, the table content has loaded but first page is not available because pagination is not rerendered. Where is the error? I debugged and I noticed that pagination <li> is ok.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Kizlo kizlo Joined 8 Dec 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.