Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8721267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:11:37+00:00 2026-06-13T07:11:37+00:00

I am trying to use Kaminari + jQuery to do endless pagination / infinite

  • 0

I am trying to use Kaminari + jQuery to do endless pagination / infinite scrolling. I am trying to append the paginated results (rows) within a table. Unfortunately, the results (row markup) appear above the table. Here’s my existing setup:

events_controller.rb

class EventsController < ApplicationController
  respond_to :html, :js

  def index
    @events = Event.all
    respond_with(@events)
  end

end

events/index.html.erb

<div id="events-container">

  <table cellpadding="3" cellspacing="0">
    <thead>
      ...
    </thead>

    <tbody>
      <% if @events.blank? %>
        <tr><td> No events yet</td></tr>
      <% else %>
        <div id="events">
          <%= render @events %>
        </div>
      <% end %>
    </tbody>
  </table>

  <nav class="pagination-container">
    <%= paginate @events %>
  </nav>​

</div>​

events/index.js.erb

$('#events').append('<%= j render(@events) %>');

<% if (@events.current_page < @events.num_pages) %>
    $('.pagination').replaceWith('<%= j paginate(@events) %>');
<% else %>
    $('.pagination-container').remove();
<% end %>

events/_event.html.erb

<tr>
  <td><%= event.time %></td>
  ...
</tr>

<tr>
  <td><%= event.location %></td>
  ...
</tr>

events_endless_paging.js

jQuery(function() {
  var isScrolledIntoView;
  isScrolledIntoView = function(elem) {
    var docViewBottom, docViewTop, elemBottom, elemTop;
    docViewTop = $(window).scrollTop();
    docViewBottom = docViewTop + $(window).height();
    elemTop = $(elem).offset().top;
    elemBottom = elemTop + $(elem).height();

    return (elemTop >= docViewTop) && (elemTop <= docViewBottom);
  };

  if ($('.pagination').length) {
    $(window).scroll(function() {
      var url;
      url = $('.pagination .next a').attr('href');
      if (url && isScrolledIntoView('.pagination')) {
        $('.pagination').text('Fetching more...');

        var script = $.getScript(url);
        return script;
      }
    });

    return $(window).scroll();
  }
});

Everything seems to be wired properly, but what ends up happening is that table rows are inserted between #event-container div and the table. So row styles are all wonky because the tags aren’t being properly inserted within the context of a table. I have the feeling that I need to insert table markup within the js response, but am not sure.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:11:38+00:00Added an answer on June 13, 2026 at 7:11 am

    I don’t think having a div inside the table body is valid.

    If you remove the div and append the new rows to the tbody directly you should have more success.

    <tbody>
      <% if @events.blank? %>
        <tr><td> No events yet</td></tr>
      <% else %>
        <%= render @events %>
      <% end %>
    </tbody>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Kaminari for pagination and trying to use meta_search for column ordering.
I am trying use the jQuery table sorter plugin for a table that is
I am need paint my image. I'm trying use JQuery in here this link:
I'm trying use jQuery to modify the HTML of the WordPress [caption] shortcode, whose
I am trying use cursor for pagination. Forwarding pagination work fine, but I can
I am trying use jQuery to poll dynamic DOM nodes, created outside of the
I'm trying use jquery ui tabs together with js and mvc3. <div class=demo> <div
I'm trying use jquery to remove a class from an element (not knowing ahead
I am trying use strtotime and date functions within a class to add a
i'm trying use facebook API to upload photo in my fan page. I downloaded

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.