1 The power of GridPanel
This chapter will explain you what functionality is by default embedded into Netzke’s grid panel.
Configuring a grid panel in the Rails view may be as simple as specifying the ActiveRecord model. It will analyze the attributes of the model and provide the convenient defaults for the columns (just as scaffolding would do):
<%= netzke :bosses,
:class_name => "GridPanel",
:model => 'Boss'
%>
Out of the box, GridPanel provides the following functionality:
- multiline CRUD-operations inside the grid itself
- multi-record editing and adding records via a form
- context menu
- support for Rails validations
- pagination
- sorting
- search filters (per column)
- configurable extended search
- automatic attribute type detection
- persistent on-the-fly configuration of the columns (“move”, “resize” and “hide”-operations)
- one-to-many associations
2 Configuring columns
In order to customize the columns, use the columns configuration option:
<%= netzke :bosses,
:class_name => "GridPanel",
:model => 'Boss',
:columns => [
:id, # id should always be included and is by default hidden
:last_name,
{:name => :salary, :editable => false, :label => "$", :renderer => 'usMoney'},
{:name => :email, :width => 180}
]
%>
2.1 Configuring column editor
TODO
2.2 Configuring column renderer
TODO
3 One-to-many associations
GridPanel supports one-to-many associations out of the box. Let’s say, we have the following models:
class Clerk < ActiveRecord::Base
belongs_to :boss
end
class Boss < ActiveRecord::Base
has_many_clerks # not really required in this example
end
Displaying a grid for the Clerk model will automatically detect the association and display it as a column with a combobox editor, which will by default allow to select a boss from all available bosses. In order to decide which method of the boss should be put into the list, GridPanel will try to see if the Boss model responds to the following methods: name, title or label. It falls back to id (thus displaying a list of the ids from the bosses table).
3.1 Specifying association method for combobox
If you want to be specific about which association method should be displayed in the drop-down list, you can use the double-underscore notation while specifying which columns must be displayed in the grid, e.g.:
<%= netzke :bosses,
:class_name => "GridPanel",
:model => 'Clerk',
:columns => [
:id, # id should always be included and is by default hidden
:last_name,
:boss__salary # this will result in a combobox listing bosses by their salary
]
%>
3.2 Scoping out combobox options
By default, GridPanel will display all the records from the associated model. However you may specify one or more scopes for an association column:
<% netzke :some_clerks,
:class_name => "GridPanel",
:model => "Clerk",
:columns => [
:id,
:first_name,
{
:name => :boss__last_name,
:editor => {
:xtype => :combobox,
:scopes => [:recently_hired, ["salary_greater_than", 95000]]
}
}
]
%>
The :scopes option for the “combobox” column editor accepts an array of named scopes. In the example above we assume that the Boss model has a scope recently_hired (taking no arguments), and a scope salary_greater_than (which accepts an argument). If a scope accepts no arguments, it can be specified as a symbol. If it requires one or more arguments, us an array, where the first element is the scope name, and the rest - the arguments.
4 Extending GridPanel
4.1 Redefining Actions
TODO
4.2 Extending Context Menu
TODO