Class: Grapple::Components::KaminariPagination

Inherits:
HtmlComponent show all
Defined in:
lib/grapple/components/kaminari_pagination.rb

Overview

Generates paging links using will_paginate.

Examples:

<%= table_for(columns, Post.paginate(page: 2)) do |t| %>
  <%= t.footer do %>
    <%= t.pagination %>
  <% end %>
<% end %>

Instance Attribute Summary

Attributes inherited from BaseComponent

#builder, #columns, #params, #records, #template

Instance Method Summary collapse

Methods inherited from BaseComponent

#initialize, setting

Constructor Details

This class inherits a constructor from Grapple::Components::BaseComponent

Instance Method Details

#render(paginate_parameters = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/grapple/components/kaminari_pagination.rb', line 17

def render(paginate_parameters = {})
	td_class = ""
	if records.instance_of?(Array)
		html = '&nbsp;'
	elsif !params[:query].blank? and records.empty?
		html = h(t(no_results_message))
		td_class = "class='text-left'"
	else
		begin
			# paginate helper will throw an error if without_count is being used
			html = template.paginate(records)
		rescue Exception => e
			html = template.link_to_prev_page(records, "Previous Page") || ""
			html += " " if html
			html += template.link_to_next_page(records, "Next Page") || ""
		end
	end

	builder.row "<td colspan=\"#{num_columns}\" #{td_class}>#{html}</td>"
end