#26 open

Find which page an item is on

Reported by Mislav | June 7th, 2007 @ 04:44 AM | in will_paginate v3.0 ("agnostic")

Joel Nylund: "Does anyone know of a pagination helper (this one or any other) that will allow me to find which page a given entity is on? So for example, if I have a list of 100 items with 20 per page, and the list is sorted by duedate, and I add a new item and I want change the page to the correct one to show the added item."

Comments and changes to this ticket

  • Chris Wanstrath

    Chris Wanstrath June 7th, 2007 @ 04:44 AM

    Here's how I did it once:

    def self.page_for_pagination(id, per_page = 10)
      return if (id = id.to_i) < 1
      query = "SELECT id FROM %s ORDER BY id DESC" % table_name
      find_by_sql(query).map(&:id).index(id).to_i / per_page + 1

    If we extract pagination logic, we could slide through a window of 200 rows or something trying to find the id...

  • Mislav

    Mislav October 8th, 2008 @ 11:11 PM

    • Milestone set to will_paginate v3.0 ("agnostic")
    • Tag set to will_paginate

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Everyone's favorite Ruby library for pagination of practically anything!

People watching this ticket