Jdagger's avatar

How to stop paginate() from jumping to the top of the page?

Hi,

So I integrated pagination for my tables, but is there any simple way (without AJAX) to make clicking the next page of the table stop going to the top of the page?

Route:

    Route::get('/beheerder', [UserController::class, 'showModPage'])->middleware('auth', 'IsVerified', 'MustBeAdmin');

Blade template:

<table class="table table-striped table-bordered table-hover" id="options">
  <strong>Lijst van opties:</strong>
  <br><br>
  <thead class="thead-dark">
      <tr>
          <th><strong>Geslachtsnaam</strong></th>
          <th><strong>Soortnaam</strong></th>
          <th><strong>Vangplaats</strong></th>
      </tr>
  </thead>
  <tbody id="table-data">
    
      @foreach ($options as $option)
      <tr>
          <td> {{ $option->geslachtsnaam }}</td>
          <td> {{ $option->soortnaam }}</td>
          <td> {{ $option->vangplaats }}</td>
      </tr>
    @endforeach
    
    <tr>
      <td colspan="3">
          {{ $options->links() }}
      </td>
  </tr>
  </tbody>
</table>

Controller method:

    public function showModPage(User $users, Options $options, Registratie $registraties) {
        $options = DB::table('options')->paginate(5);
        
        return view('/beheerder', [
            'options' => $options,
        ]);
    }
0 likes
2 replies
Jdagger's avatar

I'll edit the OP. Is it just me or is that like not a very descriptive way of making pagination() not jump to the top of the page? Sometimes the documentation is a bit confusing to me, but maybe I'm not familiar enough with the jargon. A good thing to add to the fragment() is that you should id your blade table to what you pass into the fragment() method in the controller.

Please or to participate in this conversation.