class Margrid::Builder
Utility class to ease the creation of Margrid::Grid
instances. It can be subclassed to provide more specialized behavior for your applications.
class MyBuilder < Margrid::Builder def self.articles(id: "articles", relation: Articles.all) builder = new Margrid::Grid.new(id, relation) builder.sort_by "published_at", "desc" builder end end
Attributes
grid[R]
Public Class Methods
new(grid)
click to toggle source
# File lib/margrid/builder.rb, line 15 def initialize(grid) @grid = grid end
Public Instance Methods
load(params)
click to toggle source
Deserialize Margrid
components from a hash. This is usually the case when the state using the query string.
NOTE: this method should be the last call when chaining Builder
methods. It will return the Margrid::Grid
instance and not the builder itself.
# File lib/margrid/builder.rb, line 35 def load(params) @grid.load(params) end
method_missing(sym, *args)
click to toggle source
# File lib/margrid/builder.rb, line 39 def method_missing(sym, *args) if @grid.respond_to?(sym) @grid = @grid.send(sym, *args) self end end
paginated(current_page: 1)
click to toggle source
Configure the grid to use pagination.
# File lib/margrid/builder.rb, line 20 def paginated(current_page: 1) prepend paginator: Margrid::Paginator.new(current_page) end
sort_by(column, direction)
click to toggle source
Sort the grid by column
in direction
. Direction can be :asc
or :desc
# File lib/margrid/builder.rb, line 26 def sort_by(column, direction) prepend sorter: Margrid::Sorter.new(column, direction) end