Pagination Issues

69 views
Skip to first unread message

jhstephenson

unread,
May 23, 2012, 1:59:51 PM5/23/12
to hobo...@googlegroups.com
A couple of questions about pagination:

1. I have a view where I display Customer Information and then underneath it display the products they have purchased in a Table-Plus.

The display works fine except that I do not get any pagination. All records are displayed for a customer. This isn't a big deal for customers with only a few records, but when I have some over 100 (I actually have some over 1000) it really doesn't work.

I have the following in my Products Controller:

class ProductsController < ApplicationController

  hobo_model_controller

  auto_actions :all

  def index
      hobo_index Product.apply_scopes(:search => [params[:search],:name, :date_ordered, :date_received],
      :joins=> :customer, :order_by => parse_sort_param(:date_invoiced, :name, :customer, :vendor),
      :paginate => true, :per_page => 20)
  end
 
end

Any ideas?

2. On a view for a list of customers by themselves pagination works fine, except that at the bottom of the screen I get this:

« Prev 1 2 3 4 5 11 12 Next »
« Prev 1 2 3 4 5 11 12 Next »

The pagination links are repeated twice.

Any ideas on that one?

3. While this isn't strictly related to pagination it is about the controller pasted above....

I would like the resulting table-plus view to be sorted in date_invoiced (descending) order. When I try to replace:

parse_sort_param(:date_invoiced, :name, :customer, :vendor),

with

parse_sort_param(:date_invoiced DESC, :name, :customer, :vendor),

I get errors.

Is there a different way to do that?

Thanks,
Jim

Bryan Larsen

unread,
May 25, 2012, 9:32:46 AM5/25/12
to hobo...@googlegroups.com
On Wed, May 23, 2012 at 1:59 PM, jhstephenson <jste...@scc-i.com> wrote:
> A couple of questions about pagination:
>
> 1. I have a view where I display Customer Information and then underneath it
> display the products they have purchased in a Table-Plus.
>
> The display works fine except that I do not get any pagination. All records
> are displayed for a customer. This isn't a big deal for customers with only
> a few records, but when I have some over 100 (I actually have some over
> 1000) it really doesn't work.
>
> I have the following in my Products Controller:
>
> class ProductsController < ApplicationController
>
>   hobo_model_controller
>
>   auto_actions :all
>
>   def index
>       hobo_index Product.apply_scopes(:search => [params[:search],:name,
> :date_ordered, :date_received],
>       :joins=> :customer, :order_by => parse_sort_param(:date_invoiced,
> :name, :customer, :vendor),
>       :paginate => true, :per_page => 20)
>   end
>
> end
>
> Any ideas?

What version of Hobo are you using?

I usually call the functions directly rather than using apply_scopes:
.paginate(params[:page]). apply_scopes just calls the functions
supplied as arguments, so maybe if you replace it with :paginate =>
params[:page] it will work better.

>
> 2. On a view for a list of customers by themselves pagination works fine,
> except that at the bottom of the screen I get this:
>
> « Prev 1 2 3 4 5 … 11 12 Next »
> « Prev 1 2 3 4 5 … 11 12 Next »
>
> The pagination links are repeated twice.
>
> Any ideas on that one?

Can you post your DRYML? You're probably using a tag (such as
table-plus) that includes pagination, and then adding your own
page-nav somehow...

>
> 3. While this isn't strictly related to pagination it is about the
> controller pasted above....
>
> I would like the resulting table-plus view to be sorted in date_invoiced
> (descending) order. When I try to replace:
>
> parse_sort_param(:date_invoiced, :name, :customer, :vendor),
>
> with
>
> parse_sort_param(:date_invoiced DESC, :name, :customer, :vendor),
>
> I get errors.
>
> Is there a different way to do that?
>

The parse_sort_param is so that the user can choose the sort order by
clicking on headers. If you want to choose it explicitly, just use
:order_by => "date_invoiced DESC" or .order_by("date_invoiced DESC").

If you're just looking to set the default, one way of doing it is to
set the param if it's not already set, so that parse_sort_param thinks
the user did it:

params[:sort] ||= "-date_invoiced" (remove the dash to sort in the
other direction)

Another, probably better mechanism is to use default_scope in your
model to set the default sort order.

default_scope :order => "date_invoiced DESC"

Bryan

James Stephenson

unread,
May 25, 2012, 11:12:23 AM5/25/12
to hobo...@googlegroups.com
1. Hobo 1.3.0  I will look at what you have suggested and see what I can come up with.
   

2. Here is what I have for my customer index.dryml
<index-page>
<collection: replace>
<div>
<table-plus fields="this, city, phone, products.count, status"/>
</div>
</collection:>
</index-page>

3. I like the idea of putting it in the model.


Bryan

--
You received this message because you are subscribed to the Google Groups "Hobo Users" group.
To post to this group, send email to hobo...@googlegroups.com.
To unsubscribe from this group, send email to hobousers+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/hobousers?hl=en.


Reply all
Reply to author
Forward
0 new messages