Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

HwoTo : Basic usage

giniedp edited this page · 5 revisions

Basic Ajax tables

Following code defines a grid for User records. The code belongs into a controller, a UsersController for example.

def index
  fancygrid_for :users do |user|
    # attributes we want to display  
    user.attributes :id, :username, :email 
    # callback url to this action for ajax loading
    user.ajax_url = users_path
    user.find
  end
end

Here the fancygrid is created with the name :users. The User class is guessed from the given name. However, it is possible to pass the User class and even the table name as additional options. This is needed when your models are namespaced or do not respond to #table_name.

fancygrid_for :users, :class => MyNamespace::User, :table_name => "users" do |user|
    # ...
end

The callback url must lead to the same action where the grid is defined, otherwise fancygrid is not able to display the records.

To render the grid in the view just do this:

/ app/views/users/index.html.haml
= fancygrid :users

Basic static tables

If no pagination is needed, just do not assign the ajax_url.

def index
  fancygrid_for :users do |user|
    # attributes we want to display  
    user.attributes :id, :username, :email 
    # Get the data
    user.find
  end
end
Something went wrong with that request. Please try again.