Skip to content


Bogdan Gusiev edited this page Sep 6, 2013 · 14 revisions


Simple scope definition

Datagrid scope as assets source to be queried from the database. In most cases it is a model class with some default ORM scopes like order or includes:

class ProjectsGrid
 include Datagrid
 scope { Project.includes(:category) }

Scope is also used to choose a ORM driver(MongoMapper, Mongoid or ActiveRecord), get wether filters and columns defined below has order.

You can set scope at instance level (version >= 0.9.2):

grid =[:my_grid]) do |scope|
  scope.where(:owner_id =>

grid.assets # => SELECT * FROM projects WHERE projects.owner_id = ? AND [other filtering conditions]

Scope can always be retrieved and redefined at instance level:

grid.scope # => SELECT * FROM projects WHERE projects.user_id = ?

# Reset scope to default class value
grid.reset_scope # version >= 0.9.3
grid.assets # => SELECT * FROM projects

# Overwriting the scope (ignore previously defined)
grid.scope { current_user.projects }
Something went wrong with that request. Please try again.