Generate a full customizable Ext.GridPanel
Examples:
# Returns:
# var grid = new Ext.grid.GridPanel({
# clicksToEdit: 1,
# border: false,
# bodyBorder: false,
# store: store,
# view: groupingView,
# region: "center",
# sm: new Ext.grid.CheckboxSelectionModel(),
# bbar: pagingToolbar,
# plugins: [new Ext.grid.Search()],
# viewConfig: { forceFit: true },
# id: "grid-posts",
# cm: columnModel,
# tbar: toolBar
# });
page.grid do |grid|
grid.id "grid-posts"
grid.title "List all Post"
grid.base_path "/backend/posts"
grid.forgery_protection_token request_forgery_protection_token
grid.authenticity_token form_authenticity_token
grid.tbar :default # or [:add, :edit, :delete] or [:edit, :delete]
grid.store do |store|
store.url "/backend/posts.json"
store.fields @column_store.store_fields
end
grid.columns do |columns|
columns.fields @column_store.column_fields
end
grid.bbar :store => grid.get_store, :pageSize => params[:limit]
end
# Returns:
# var grid = new Ext.grid.EditorGridPanel({
# clicksToEdit: 1,
# ...
page.grid :editable => true do |grid|
grid.id "grid-posts"
...
- authenticity_token
- base_path
- bbar
- columns
- destroy_path
- edit_path
- forgery_protection_token
- get_selected
- new_path
- render
- sm
- store
- tbar
- to_s
- view
The authenticity_token used for ToolBar
[ show source ]
# File lib/view/helpers/ext/grid.rb, line 241
241: def authenticity_token(value)
242: @authenticity_token = value
243: end
[ show source ]
# File lib/view/helpers/ext/grid.rb, line 216
216: def base_path(value)
217: @base_path = value
218: end
Generate or set a new Ext.Toolbar
Examples:
bbar: new Ext.PagingToolbar({
pageSize: <%= params[:limit] %>,
store: js,
displayInfo: true
})
bbar :pageSize => params[:limit], :store => store.get_var, displayInfo: true
[ show source ]
# File lib/view/helpers/ext/grid.rb, line 166
166: def bbar(object=nil, &block)
167: bbar = object.is_a?(Hash) ? Component.new("Ext.PagingToolbar", object.merge(:prefix => get_var)) : object
168: add_object(:bbar, bbar)
169: end
Generate or set new Ext.grid.ColumnModel
[ show source ]
# File lib/view/helpers/ext/grid.rb, line 197
197: def columns(object=nil, &block)
198: options = { :columns => [] }
199: if config[:sm] && before.find { |js| js.start_with?("var #{config[:sm]} = new Ext.grid.CheckboxSelectionModel") }
200: options[:columns] << config[:sm]
201: end
202: cm = object.is_a?(ColumnModel) ? value : ColumnModel.new(options.merge(:prefix => get_var), &block)
203: add_object(:cm, cm)
204: end
[ show source ]
# File lib/view/helpers/ext/grid.rb, line 231
231: def destroy_path(value)
232: @destroy_path = value
233: end
[ show source ]
# File lib/view/helpers/ext/grid.rb, line 226
226: def edit_path(value)
227: @edit_path = value
228: end
The forgery_protection_token used for ToolBar
[ show source ]
# File lib/view/helpers/ext/grid.rb, line 236
236: def forgery_protection_token(value)
237: @forgery_protection_token = value
238: end
Returns getSelectionModel().getSelected()
Examples:
# Generates: grid.getSelectionModel().getSelected().id
grid.get_selected
# Generates: getSelectionModel().getSelected().data['name']
grid.get_selected(:name)
[ show source ]
# File lib/view/helpers/ext/grid.rb, line 255
255: def get_selected(data=:id)
256: raise_error "No Column Selection Model Defined" if config[:sm].blank?
257: if data.to_sym == :id
258: "#{config[:sm]}.getSelected().id".to_l
259: else
260: "#{config[:sm]}.getSelected().data[#{data.to_json}]"
261: end
262: end
[ show source ]
# File lib/view/helpers/ext/grid.rb, line 221
221: def new_path(value)
222: @new_path = value
223: end
Define if the grid need to be added to
Backend.app.addItem(#{get_var});
[ show source ]
# File lib/view/helpers/ext/grid.rb, line 211
211: def render(value)
212: @render = value
213: end
Define the selection model of this grid. You can pass:
- :checkbox || :default
- :row
- custom (eg. Component.new("some"))
It generate some like:
new Ext.grid.CheckboxSelectionModel()
[ show source ]
# File lib/view/helpers/ext/grid.rb, line 89
89: def sm(object)
90: selmodel = case object
91: when :default then Component.new("Ext.grid.CheckboxSelectionModel", :prefix => get_var)
92: when :checkbox then Component.new("Ext.grid.CheckboxSelectionModel", :prefix => get_var)
93: when :row then Component.new("Ext.grid.RowSelectionModel", :prefix => get_var)
94: else object
95: end
96: add_object(:sm, selmodel)
97: end
Generate or set a new Ext.data.GroupingStore
[ show source ]
# File lib/view/helpers/ext/grid.rb, line 191
191: def store(object=nil, &block)
192: store = object.is_a?(Store) ? object : Store.new(:prefix => get_var, &block)
193: add_object(:store, store)
194: end
Generate or set a new Ext.Toolbar You can pass tbar :default options that will create defaults buttons for add, edit and remove records, it‘s generate also the javascript for manage them. for use this you need to set for the grid the: base_path, forgery_protection_token, authenticity_token and store.
Examples:
var toolBar = new Ext.Toolbar([{
handler: add,
disabled: false,
text: Backend.locale.buttons.add,
cls: "x-btn-text-icon add",
id: "add"
},{
handler: edit,
disabled: true,
text: Backend.locale.buttons.edit,
cls: "x-btn-text-icon edit",
id: "edit"
},{
handler: remove,
disabled: true,
text: Backend.locale.buttons.remove,
cls: "x-btn-text-icon remove",
id: "remove"
}]);
tbar :default
[ show source ]
# File lib/view/helpers/ext/grid.rb, line 129
129: def tbar(object=nil, &block)
130: tbar = object.is_a?(ToolBar) ? object : ToolBar.new(:prefix => get_var)
131: if object == :default || object == :all
132: tbar.add_button :text => "Backend.locale.buttons.add".to_l, :id => "add", :disabled => false, :cls => "x-btn-text-icon add", :handler => "add".to_l
133: tbar.add_button :text => "Backend.locale.buttons.edit".to_l, :id => "edit", :disabled => true, :cls => "x-btn-text-icon edit", :handler => "edit".to_l
134: tbar.add_button :text => "Backend.locale.buttons.remove".to_l, :id => "remove", :disabled => true, :cls => "x-btn-text-icon remove", :handler => "remove".to_l
135: @ttbar_add, @ttbar_edit, @ttbar_delete = true, true, true
136: end
137: if object.is_a?(Array)
138: object.each do |button|
139: case button
140: when :add
141: tbar.add_button :text => "Backend.locale.buttons.add".to_l, :id => "add", :disabled => false, :cls => "x-btn-text-icon add", :handler => "add".to_l
142: @ttbar_add = true
143: when :edit
144: tbar.add_button :text => "Backend.locale.buttons.edit".to_l, :id => "edit", :disabled => true, :cls => "x-btn-text-icon edit", :handler => "edit".to_l
145: @ttbar_edit = true
146: when :delete
147: tbar.add_button :text => "Backend.locale.buttons.remove".to_l, :id => "remove", :disabled => true, :cls => "x-btn-text-icon remove", :handler => "remove".to_l
148: @ttbar_delete = true
149: end
150: end
151: end
152: yield tbar if block_given?
153: add_object(:tbar, tbar)
154: end
Return the javascript for create a new Ext.grid.GridPanel
[ show source ]
# File lib/view/helpers/ext/grid.rb, line 265
265: def to_s
266: if @ttbar_add || @ttbar_edit || @ttbar_delete
267: raise_error "You must provide the base_path for autobuild toolbar." if @base_path.blank? && @new_path.blank? && @edit_path.blank? && @destroy_path.blank?
268: raise_error "You must provide the new_path for autobuild button new of toolbar." if @base_path.blank? && @new_path.blank?
269: raise_error "You must provide the edit_path for autobuild button edit of toolbar." if @base_path.blank? && @edit_path.blank?
270: raise_error "You must provide the destroy_path for autobuild button destroy of toolbar." if @base_path.blank? && @destroy_path.blank?
271: raise_error "You must provide the forgery_protection_token for autobuild toolbar." if @forgery_protection_token.blank?
272: raise_error "You must provide the authenticity_token for autobuild toolbar." if @authenticity_token.blank?
273: raise_error "You must provide the grid for autobuild toolbar." if get_var.blank?
274: raise_error "You must provide the selection model for autobuild toolbar." if config[:sm].blank?
275: raise_error "You must provide the store." if config[:store].blank?
276: end
277:
278: after << render_javascript(:grid_functions, :var => get_var, :store => config[:store], :sm => config[:sm], :tbar => config[:tbar], :editable => @editable, :un => @un)
279:
280: if @render
281: after << "Backend.app.addItem(#{get_var});" if @render
282: if config[:store]
283: after << "#{config[:store]}.on('beforeload', function(){ Backend.app.mask(); });"
284: after << "#{config[:store]}.on('load', function(){ Backend.app.unmask(); });"
285: after << "#{config[:store]}.load();"
286: end
287: end
288: super
289: end
Generate or set a new Ext.grid.GroupingView You can pass view :default options that will autocreate a correct GroupingView
Examples:
view: new Ext.grid.GroupingView({
forceFit:true,
groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Foo" : "Bar"]})'
})
view :forceFit => true, :groupTextTpl => '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Foo" : "Bar"]})'
[ show source ]
# File lib/view/helpers/ext/grid.rb, line 181
181: def view(object=nil, &block)
182: view = case object
183: when :default then Component.new("Ext.grid.GroupingView", { :forceFit => true, :prefix => get_var })
184: when Hash then Component.new("Ext.grid.GroupingView", { :forceFit => true, :prefix => get_var }.merge(object))
185: else object
186: end
187: add_object(:view, view)
188: end