Username
Username

Reputation: 3663

How do I load more table rows while scrolling?

My guess is that I must add a 'post do' statement to my .rb file, though I'm still new to Sinatra and unfamiliar with how to load more content once the browser has scrolled to the bottom of the page.

Here's an example of my .rb file:

get '/' do
  @arr = []
  (1..1000).each{ |x| @arr << x }
  erb :test
end

And here's an example of my .erb file:

<table>

  <thead>
    <tr><td>Number</td></th>
  </thead>

  <tbody>
  <% @arr.each do |number| %>
    <tr><td><%= number %></td></tr>
  <% end %>
  </tbody>

</table>

Of course, I wouldn't want all 1,000 rows to load. Instead, it would nice for just the first 10 to load, then the next 10 when the user scrolls to the bottom, and so on.

Does anyone know how I can learn this for Sinatra?

Upvotes: 1

Views: 1181

Answers (1)

user1193509
user1193509

Reputation:

I don't know Sinatra, but you can embed Javascript functions that fire on scroll events.

Javascript onscroll event help

Upvotes: 2

Related Questions