g_already_grid
github.com/midas/g_already_grid/tree/master
DESCRIPTION:
A Guilded (github.com/midas/guilded/tree/master) Rails component that generates a rich grid control from an ActiveRecord collection.
FEATURES:
-
Easily generate a rich grid from an ActiveRecord collection
-
Can integrate with mislav-will_paginate to provide paging controls
-
Can generate sorting links in headers
-
Can do a check box column for multi-selecting
-
Automatically renders a check all and adds check all behavior if check box column option
COMPATABILITY
-
Ruby 1.9
-
Ruby 1.8
-
Rails 3
-
Rails 2
INSTALL:
gem install g_already_grid
INSTALL FOR RAILS
Configure the Gem for use:
gem 'g_already_grid' # Rails 3
config.gem 'g_already_grid' # Rails 2
Install the Gem:
bundle install # Rails 3
rake gems:install # Rails 2
Generate:
rails generate already_grid_assets_generator # Rails 3
script/generate already_grid_assets_generator # Rails 2
USAGE:
Simplest case:
<%= raw g_already_grid( @items, :id => "items-grid", :cols => [:name, :is_active] ) %> # Rails 3
<%= g_already_grid @items, :id => "items-grid", :cols => [:name, :is_active] %> # Rails 2
Add sorting (by name column only):
<%= g_already_grid @items, :id => "items-grid", :cols => [:name, :is_active], :sort => [:name] %> # Rails 2
Add scoping for nested models (deeply nested):
<%= g_already_grid @items, :id => "items-grid", :cols => [:name, :is_active], :sort => [:name], # Rails 2
:scoped_by => @account %>
Add shallow option to use shallow nesting:
<%= g_already_grid @items, :id => "items-grid", :cols => [:name, :is_active], :sort => [:name], # Rails 2
:scoped_by => @account, :shallow => true %>
Add namespace option for namespacing:
<%= g_already_grid @items, :id => "items-grid", :cols => [:name, :is_active], :sort => [:name], # Rails 2
:namespace => :admin %>
Add use polymorphic path option for STI’ed models:
<%= g_already_grid @items, :id => "items-grid", :cols => [:name, :is_active], :sort => [:name], # Rails 2
:namespace => :admin, :use_polymorphic_path => true %>
OPTIONS:
- id
-
The HTML id attribute.
- cols
-
(required) An array of column names to include in the table. Each position of the array can be a symbol, string, or hash with 1 entry. The hash entry is the database field name as a key and the name to use in the gird as the value. Each key and value in the hash can be a symbol or string.
- skin
-
The name of the skin to use for this Guilded element. Defaults to default => which is default.css.
- exclude_css
-
A boolean indicating if Guilded should create a stylesheet include tag for this element. Defaults to false.
- empty_msg
-
a message to display when the ar_col is empty or nil. Defaults to ‘No matching records’.
- actions
-
Action links to include in the action column of grid. A boolean or Array of symbols. When boolean, if true, add show, edit and delete actions. When boolean, if false, hide actions column. When Array of symbols, add only actions present in array.
- paginate
-
A boolean indicating whether to output pagination controls. Defaults to true. Utilizes will_paginate plugin features.
- polymorphic_type
-
The type of this polymorphic record. Should be a string representing the class name.
- polymorphic_as
-
The as used for the polymorphic type. Can be a symbol or string.
- use_polymorphic_path
-
When true, uses the polymorphic path helper to determine the AR objects path from it’s type (STI), otherwise, does not. Defaults to false.
- use_sti_base_index
-
When true, use the STI base class’ index path instead of the specific descendant AR object’s.
- namespace
-
A string or symbol that is the namespace this collection is under.
- scoped_by
-
The active record object that the objects in the ar_col is scoped by.
- shallow
-
True if this collection is nested shallow, otherwise, false.
- clickable
-
Set to false in order to avoid rows linking to show action. Defaults to true.
- adaptable_url
-
True in order to make the index url automagically adapt to :get collection routes, otherwise false.
Overriding HTML generation
You can override the following methods in your application_helper.rb file:
-
g_already_grid_empty_message( options={} )
-
g_already_grid_non_sortable_column_title( title )
-
g_already_grid_sortable_column_title( name, method, path, scoping_args, controller, already_grid_options, options={} )
-
g_already_grid_footer_contents( ar_col, options={} )
REQUIREMENTS:
-
Rails >= 2.2.0
-
Guilded >= 1.0.0 (github.com/midas/guilded/tree/master)
-
will_paginate
LICENSE:
(The MIT License)
Copyright © 2009 C. Jason Harrelson (midas)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.