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 8912941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:20:27+00:00 2026-06-15T04:20:27+00:00

I currently have a working table that is sorted by several select boxes. I

  • 0

I currently have a working table that is sorted by several select boxes. I recently implemented endless/infinite scrolling by following this tutorial: http://railscasts.com/episodes/114-endless-page-revised?view=asciicast

The tutorial worked after a couple of changes, but I have one problem. I am using a counter for the first column, but the problem is that every time it loads the next page, the counter resets to 1, so the counter is like 1..2..3.. all the way to 50, but when I scroll to the bottom, it resets to 1. I am currently displaying 50 records at the start and 50 more each time the user scrolls down to the bottom. I would like the next records to be 51…52…53…etc. Then the next time you scroll to the bottom, start at 101 then 102…103…104…etc., like for example a ranking list.

To get the partial I followed this tutorial which also told me how to make the counter column:
http://xianese.blogspot.com/2008/06/render-collection.html

After doing some research, I figured out that the counter I am using is pretty much undocumented, and several people have reported a pagination issue with it, which means that it is not just an issue with infinite scrolling, but with pagination (I am using will_paginate). On one website, a person said that they had solved the pagination issue, but then did not say how, and the post is now closed, so I know that there is a way to fix this issue.

This is a link to that website:
http://www.pgrs.net/2007/07/20/render-partial-with-collection-has-hidden-counter/

Anything that could help me would be greatly appreciated.

Here is my code:

articles.js.coffee

jQuery ->
   if $('.pagination').length
      $('#articles_table').scroll ->
              url = $('.pagination .next_page').attr('href')          
              if url &&  $('#articles_table')[0].scrollHeight -    
              $('#articles_table').scrollTop() < 700                  
                      $('.pagination').text('Fetching more users...')
                      $.getScript(url)
$('#articles_table').scroll()

index.html.erb

<table class="table table-striped table-bordered span8 table-condensed"     
 id="articles_table" >
<thead class="header">
  <tr>
      <th>ID</th>
      <th>Title</th>
      <th>Description</th>
      <th>Created_At</th>
  </tr>
</thead>
<tbody>
<%= render @articles %>

</tbody>

index.js.erb

$('#articles_table').append('<%= j render(@articles) %>');
<% if @articles.next_page %>
$('.pagination').replaceWith('<%= j will_paginate(@articles) %>');
<% else %>
$('.pagination').remove();
<% end %>

_article.html.erb

<tr>
      <td> <%= article_counter +1 %> </td>
      <td> <%= article.Title %> </td>
      <td> <%= article.Description %> </td>
      <td> <%= article.Created_At %> </td>
</tr>

Thanks,

Jack

  • 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-15T04:20:28+00:00Added an answer on June 15, 2026 at 4:20 am

    After a ton of research, I came upon this stack overflow post which was different than mine because it was using an index, but the code worked for me!
    persistent counter in Ruby/Rails for each

    Here is the code that I added to _article.html.erb:

    <% if params[:page].nil? || params[:page] == "0" || params[:page] == "1" %>
      <% x = 0 %>
    <% else %>
      <% page = params[:page].to_i - 1 %>
      <% x = page * 50 %>
    <% end %>
    

    I just added an x to it so it’s: article_counter + x + 1, with x being defined in the above code. Here is what the whole file looks like:

    <% if params[:page].nil? || params[:page] == "0" || params[:page] == "1" %>
          <% x = 0 %>
        <% else %>
          <% page = params[:page].to_i - 1 %>
          <% x = page * 50 %>
        <% end %>
    <tr>
          <td> <%= article_counter +1 %> </td>
          <td> <%= article.Title %> </td>
          <td> <%= article.Description %> </td>
          <td> <%= article.Created_At %> </td>
    </tr>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working rearchitecting a reporting/data warehouse type database. We currently have a table that
I currently have working code that inserts rows into a table. It looks like
I'm currently working with MS SQL 2005, and have a table that has 17
I have jQuery draggable set up and working ok on a table row. Currently
I am working on splitting out an existing, working application that I currently have
I have data in a table that looks like the following sample data: varchar(20)
I have an application I'm currently working on that requires Administrators to be able
I am working on a project where I have a table view that is
THE INFO Currently I have two tables I am working with- a POST table
I currently have a gridview that is set up and working properly but I

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.