Below is an instance of GridPanel, which by default provides for:
Code (in the view):
netzke :bosses, :class_name => "Basepack::GridPanel", :model => 'Boss'
Result:
If you need more control over which columns to display and how, you can provide :columns option:
netzke :bosses_custom_columns, :class_name => "Basepack::GridPanel", :model => 'Boss', :title => "Bosses", :width => 400, :columns => [ :last_name, {:name => :salary, :read_only => true, :label => "$", :renderer => 'usMoney'}, {:name => :email, :width => 180}]
Result:
Here's an example that demonstrates:
# Model class Clerk < ActiveRecord::Base belongs_to :boss validates_presence_of :first_name validates_presence_of :last_name # a virtual attribute def name "#{last_name}, #{first_name}" end def updated updated_at > 5.minutes.ago end end # Extend GridPanel to be specific about the model and columns we want to display class ClerkGrid < Netzke::Basepack::GridPanel css_include :main def configuration super.merge({ :model => "Clerk", # Declaring columns :columns => [ { :name => :name, :renderer => "uppercase", :width => 200 }, :first_name, :last_name, { :name => :updated_bulb, :width => 40, :label => "<div class='bulb-off' />", :tooltip => "Recently updated", :getter => lambda { |r| bulb = r.updated ? "on" : "off" "<div class='bulb-#{bulb}' />" } }, :email, { :name => :boss__last_name, :scope => {:salary.gt => 95000}, :header => "Boss" } ] }) end end # In the view: netzke :clerk_grid
Result:
netzke :bosses_with_permissions, :class_name => "Basepack::GridPanel", :model => 'Boss', :prohibit_update => true, :prohibit_delete => true
Result:
A word about the security: it's not only about disabling buttons. Even if the user manages to submit a prohibited operation, the server side of the widget will block the attempt.
You can easily customize the bottom bar, or even move the actions to the top bar.
netzke :clerks_with_custom_bottom_bar, :class_name => "Basepack::GridPanel", :model => 'Clerk', :bbar => nil, :tbar => [{ :menu => [:add.action, :edit.action, :apply.action, :del.action], :text => "Edit inline", :icon =>"/images/icons/table.png" },{ :menu => [:add_in_form.action, :edit_in_form.action], :text => "Edit in form", :icon => "/images/icons/application_form.png" }]
Result:
Netzke framework consists of 2 Rails plugins/Ruby gems: netzke-core and netzke-basepack. Get them on the GitHub along with the source code for this demo: http://github.com/skozlov
The news about Netzke development and more tutorials on http://blog.writelesscode.com
--- The following links alter test data (the page will be reloaded):
reset configs (e.g. columns configurations, permissions, etc )