Skip to content

Commit

Permalink
first attempt with kaminari
Browse files Browse the repository at this point in the history
  • Loading branch information
leikind committed Jul 26, 2012
1 parent 6e0fdd6 commit 6ee9256
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
26 changes: 17 additions & 9 deletions lib/helpers/wice_grid_view_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -583,12 +583,14 @@ def pagination_panel_content(grid, extra_request_parameters, allow_showing_all_r

html = pagination_info(grid, allow_showing_all_records)

will_paginate(grid.resultset,
:previous_label => NlMessage['previous_label'],
:next_label => NlMessage['next_label'],
:param_name => "#{grid.name}[page]",
:renderer => ::Wice::WillPaginatePaginator,
:params => extra_request_parameters).to_s +
# will_paginate(grid.resultset,
# :previous_label => NlMessage['previous_label'],
# :next_label => NlMessage['next_label'],
# :param_name => "#{grid.name}[page]",
# :renderer => ::Wice::WillPaginatePaginator,
# :params => extra_request_parameters).to_s +

paginate(grid.resultset, :param_name => "#{grid.name}[page]") +
(' <div class="pagination_status">' + html + '</div>').html_safe_if_necessary
end

Expand Down Expand Up @@ -624,17 +626,23 @@ def back_to_pagination_link(parameters, grid_name) #:nodoc:
def pagination_info(grid, allow_showing_all_records) #:nodoc:
collection = grid.resultset

collection_total_entries = collection.total_entries
collection_total_entries = collection.total_count
collection_total_entries_str = collection_total_entries.to_s

current_page = grid.ar_options[:page].to_i
per_page = grid.ar_options[:per_page].to_i

offset = per_page * (current_page - 1)

parameters = grid.get_state_as_parameter_value_pairs

js = ''
html = if (collection.total_pages < 2 && collection.length == 0)
html = if (collection.num_pages < 2 && collection.length == 0)
'0'
else
parameters << ["#{grid.name}[pp]", collection_total_entries_str]

"#{collection.offset + 1}-#{collection.offset + collection.length} / #{collection_total_entries_str} " +
"#{offset + 1}-#{offset + collection.count} / #{collection_total_entries_str} " +
if (! allow_showing_all_records) || collection_total_entries <= collection.length
''
else
Expand Down
18 changes: 16 additions & 2 deletions lib/wice_grid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,27 @@ def form_ar_options(opts = {}) #:nodoc:
@ar_options[:select] = @options[:select]
end


# TO DO: what to do with other @ar_options values?
def read #:nodoc:
form_ar_options
@klass.unscoped do
@resultset = if self.output_csv?
@relation.find(:all, @ar_options)
# @relation.find(:all, @ar_options)
@relation.
includes(@ar_options[:include]).
joins( @ar_options[:joins]).
where( @ar_options[:conditions])

else
@relation.paginate(@ar_options)
# p @ar_options
@relation.
page( @ar_options[:page]).
per( @ar_options[:per_page]).
includes(@ar_options[:include]).
joins( @ar_options[:joins]).
where( @ar_options[:conditions])

end
end
invoke_resultset_callbacks
Expand Down

0 comments on commit 6ee9256

Please sign in to comment.