Class: Grapple::Components::WillPaginatePagination

Inherits:
HtmlComponent show all
Defined in:
lib/grapple/components/will_paginate_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
# File 'lib/grapple/components/will_paginate_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
		paginate_parameters[:param_name] = url_parameter(:page) if builder.namespace
		options = { renderer: renderer }.select { |_, value| !value.nil? }.merge(paginate_parameters)
		html = template.will_paginate(records, options) || '&nbsp;'
	end

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