bilal1112 / Laravel-Pagination-jQuery-Plugin

Laravel pagination without refresh jQuery plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Laravel-Pagination

Laravel pagination without refresh jQuery plugin

Getting Started

Installation

Add script file in your code

 <script src="/path/to/paginate.min.js"></script>

Usage

put your code section where you want to apply pagination in partial view and include that view in parent blade file wrap up your include view with div and given an id attribute

Example

in parent view

<div id='list'>
   @include('child')
</div>

in child view

<div class="table-responsive">          
  <table class="table">
    <thead>
      <tr>
        <th>#</th>
        <th>Firstname</th>
        <th>Lastname</th>
      </tr>
    </thead>
    <tbody>
      @foreach($users as $user)
        <tr>
          <td>{{$user->id}}</td>
          <td>{{$user->first_name}}</td>
          <td>{{$user->last_name}}</td>
        </tr>
      @endforeach
    </tbody>
  </table>
</div>
{{$users->links()}}

Call Laravel paginate plugin

   $('#list').paginate();

in controller function change the return value like this:

    public function index(Request $request){
      // code goes here

      if ($request->ajax()) {
          return response()->json(view('child',$users)->render(),200);
      }

      return view('parent', $users);
    }

Demo

enter image description here

About

Laravel pagination without refresh jQuery plugin

License:GNU General Public License v3.0


Languages

Language:JavaScript 100.0%