Class: ExtGrid
- Includes:
- Magic::Store, Magic::Title
- Defined in:
- lib/extclasses/grid.rb
Constant Summary collapse
- @@ALIAS_CONFIG =
{ :text => :title }
Instance Attribute Summary
Attributes inherited from ExtNode
#childs, #config, #deep_lvl, #default_config, #parent, #xtype
Instance Method Summary collapse
- #default_page_size ⇒ Object
-
#initialize(config, parent) ⇒ ExtGrid
constructor
A new instance of ExtGrid.
-
#to_extjs(at_deep = 0) ⇒ Object
TODO refactor.
Methods included from Magic::Title
Methods included from Magic::Store
Methods inherited from ExtNode
#add_child, #apply_config, before_to_extjs, #build_abstract_function, #child_of?, #child_of_form?, #collect_events, #collect_ref, #conv_id_to_label, #conv_id_to_name, #conv_id_to_ref, #do_alias_config, #do_layout, #find, #find_field_elements, #find_parent, #get_all_siblings, get_before_filters, #get_deep, get_events, get_refs, #has_child?, #is_field_element?, #override_config, #prepare_config, #remove_childs, #remove_config, reset_generator_config, #root?, set_generator_config, #set_parent
Constructor Details
#initialize(config, parent) ⇒ ExtGrid
Returns a new instance of ExtGrid.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/extclasses/grid.rb', line 9 def initialize(config, parent) @default_config = { title: "My Grid", # enableHdMenu: false, columnLines: true, sm: "", selector: "row", # enableColumnmove: false, viewConfig: { forceFit: true, emptyText: "No record" # for expanding row to show any infomation # enableRowBody: true }, frame: false, width: "auto", loadMask: true, # TODO dummy store store: [], height: 200 # columns: [ # { id: 'company', header: 'Company', width: 200, sortable: true, dataIndex: 'company'}, # { header: 'Price', dataIndex: 'price'}, # { header: 'Change', dataIndex: 'change'}, # { header: '% Change', dataIndex: 'pctChange'}, # { # header: 'Last Updated', width: 135, dataIndex: 'lastChange', # xtype: 'datecolumn', format: 'M d, Y' # } # ] } super('grid',config, parent) end |
Instance Method Details
#default_page_size ⇒ Object
138 139 140 |
# File 'lib/extclasses/grid.rb', line 138 def default_page_size 25 end |
#to_extjs(at_deep = 0) ⇒ Object
TODO refactor
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/extclasses/grid.rb', line 45 def to_extjs(at_deep = 0) # columns cols = [] self.childs.each do |c| cols << c.to_extjs(at_deep) unless c.xtype.match(/column$/).nil? end @config.merge! :columns => cols unless cols.nil? # rowselection type : row | rows, cell | cells, checkbox | checkboxs # # unless @config[:selector].nil? # # generate random js variable name # require "securerandom" # var = SecureRandom.urlsafe_base64.gsub(/\d|\W/,'') # case @config[:selector] # when "row" # @config.merge! :sm => "<js>(this._#{var} = new Ext.grid.RowSelectionModel({ singleSelect: true }))</js>)" # when "rows" # @config.merge! :sm => "<js>(this._#{var} = new Ext.grid.RowSelectionModel({ singleSelect: false }))</js>)" # # TODO # # when "cell" # # @config.merge! :sm => "<js>(this._#{var} = new Ext.grid.CellSelectionModel())</js>)" # when "checkbox" # @config.merge! :sm => "<js>(this._#{var} = new Ext.grid.CheckboxSelectionModel({ singleSelect: true, header: '' }))</js>)" # @config[:columns].unshift("<js>this._#{var}</js>") # when "checkboxs" # @config.merge! :sm => "<js>(this._#{var} = new Ext.grid.CheckboxSelectionModel())</js>)" # @config[:columns].unshift("<js>this._#{var}</js>") # end # @config.delete :selector # end = self.find("toolbar", {recursive: 1}) @config.merge! :tbar => .to_extjs(at_deep + 1) if rand_store_id = nil if @config[:store] == [] data_xtype = ExtUtil.data_xtype data_cols = [] @config[:columns].each do |c| if c.is_a? Hash if data_xtype.include? c[:xtype] data_cols << "{ name: '#{c[:dataIndex]}' }" end end end rand_store_id = ExtUtil.random_id if @config[:restful] @config[:url] = @config[:restful] end fetch_type = @config[:url] ? (@config[:restful] ? "rest" : "ajax") : "memory" if data_cols.count > 0 @config[:store] = %Q{ <js>( this.#{rand_store_id} = new Ext.data.JsonStore({ storeId: \"#{rand_store_id}\", pageSize: #{@config[:pageSize] || default_page_size}, proxy: { url: \"#{@config[:url]}\", type: \"#{fetch_type}\", reader: { type: \"json\", root: \"data\" } }, fields: [#{data_cols.join(',')}] })) </js>}.strip # remove internal usaged config @config.delete :url @config.delete :restful end @config.delete :pageSize # auto create json store end # set paging paging = self.find("pagingtoolbar") if paging paging.override_config :store => ("<js>this.#{rand_store_id}</js>" || @config[:store]) unless @config[:store] =~ /<js>/ paging.override_config :store => (rand_store_id || @config[:store]) end @config.merge! :bbar => paging.to_extjs(at_deep + 1) end # grid does not allow to have items self.childs = [] super(at_deep) end |