Skip to content

Commit

Permalink
option :total_entries
Browse files Browse the repository at this point in the history
  • Loading branch information
leikind committed Nov 11, 2009
1 parent 1d00b82 commit 50b83b1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -1,4 +1,6 @@

:total_entries parameter added to initialize_grid (will_paginate)

Localization

assert_keys wherever possible
Expand Down
7 changes: 4 additions & 3 deletions lib/wice_grid.rb
Expand Up @@ -67,7 +67,8 @@ def initialize(klass, controller, opts = {}) #:nodoc:
:order_direction => Defaults::ORDER_DIRECTION,
:page => 1,
:per_page => Defaults::PER_PAGE,
:saved_query => nil
:saved_query => nil,
:total_entries => nil
}

# validate parameters
Expand Down Expand Up @@ -104,6 +105,7 @@ def initialize(klass, controller, opts = {}) #:nodoc:
@status[:order] = @options[:order]

end
@status[:total_entries] = @options[:total_entries]
@status[:per_page] = @options[:per_page]
@status[:page] = @options[:page]
@status[:conditions] = @options[:conditions]
Expand Down Expand Up @@ -187,7 +189,6 @@ def form_ar_options(opts = {}) #:nodoc:

@ar_options[:conditions] = @status[:conditions]


if @table_column_matrix.generated_conditions.size == 0
@status.delete(:f)
end
Expand All @@ -205,6 +206,7 @@ def form_ar_options(opts = {}) #:nodoc:
if self.output_html?
@ar_options[:per_page] = @status[:pp] || @status[:per_page]
@ar_options[:page] = @status[:page]
@ar_options[:total_entries] = @status[:total_entries] if @status[:total_entries]
end

@ar_options[:joins] = @options[:joins]
Expand All @@ -213,7 +215,6 @@ def form_ar_options(opts = {}) #:nodoc:

def read #:nodoc:
form_ar_options
# Wice.log(@ar_options.to_yaml)
@resultset = self.output_csv? ? @klass.find(:all, @ar_options) : @klass.paginate(@ar_options)
end

Expand Down
5 changes: 4 additions & 1 deletion lib/wice_grid_controller.rb
Expand Up @@ -47,7 +47,10 @@ def save_wice_grid_queries
# Read section "Saving Queries How-To" in README for more details.
# * <tt>:after</tt> - defined a name of a controller method which would be called by the grid after all user input has been processed,
# with a single parameter which is a Proc object. Once called, the object returns a list of all records of the current selection
# throughout all pages. See section "Integration With The Application" in the README.
# throughout all pages. See section "Integration With The Application" in the README.
# * <tt>:total_entries</tt> - If not specified, <tt>will_paginate</tt> will run a <tt>select count</tt>
# query to calculate the total number of entries. If specified, the value is passed on to <tt>:total_entries</tt> of
# will_paginate's <tt>paginate</tt> method.
#
# Defaults for parameters <tt>:per_page</tt>, <tt>:order_direction</tt>, <tt>:name</tt>, and <tt>:erb_mode</tt>
# can be changed in <tt>lib/wice_grid_config.rb</tt>, this is convenient if you want to set a project wide setting
Expand Down

0 comments on commit 50b83b1

Please sign in to comment.