我尝试在面板的南部区域制作一个带有一个主网格和子网格的 Netzke 组件。When a row in the maingrid is selected then should the subgrids be filtered with records related to the record in maingrid - like described here for an old netzke version:
https://groups.google.com/forum/#!searchin/netzke/tabpanel/netzke/PFAQ-wYyNog/2RJgRLzh80oJ
我知道 netzke 没有进一步开发,但我在项目中使用它。
红宝石 2.1.2 (Mac OSX rbenv)
导轨 4.0.10
netzke-core v0.10.1
netzke-basepack v0.10.1
这是我的代码:
楷模:
class MbOrganisation < ActiveRecord::Base
has_many :mb_contacts
def customer_name
"#{orga_customer} - #{orga_name1}"
end
end
class MbContact < ActiveRecord::Base
belongs_to :mb_organisation
end
这是中心组件 app/components/organisation_multitab.rb
class OrganisationMultitab < Netzke::Base
component :organisation_organisations
component :organisation_tabpanel do |c|
c.klass = MblixBaseTabpanel
c.items = [:organisation_contacts]
end
js_configure do |c|
c.layout = :border
c.border = false
c.init_component = <<-JS
function(){
// calling superclass's initComponent
this.callParent();
// setting the 'rowclick' event
var view = this.netzkeGetComponent('organisation_organisations').getView();
view.on('itemclick', function(view, record){
// The beauty of using Ext.Direct: calling 3 endpoints in a row, which results in a single call to the server!
this.selectItem({item_id: record.get('id')});
}, this);
}
JS
end
def configure(c)
super
c.items = [
{ items: [:organisation_organisations], region: :center },
{ items: [:organisation_tabpanel], region: :south, height: 200, split: true }
]
end
endpoint :select_item do |params, this|
# store selected id in the session for this component's instance
component_session[:selected_item_id] = params[:item_id]
end
end
这些组件额外使用 Maingrid - organization_organisations.rb
class OrganisationOrganisations < Netzke::Basepack::Grid
def configure(c)
super
c.model = "MbOrganisation"
c.columns = [:orga_customer, :orga_name1, :orga_name2, :orga_street, :orga_zip, :orga_city, :orga_tel, :orga_email]
c.force_fit = true
end
end
带有 Tabpanel-base_tabpanel.rb 的组件:
class BaseTabpanel < Netzke::Basepack::TabPanel
component :organisation_contacts do |c|
c.data_store = {auto_load: false}
c.scope = {:mb_organisation_id => component_session[:selected_item_id]}
c.strong_default_attrs = {:mb_organisation_id => component_session[:selected_item_id]}
end
def configure(c)
super
c.active_tab = 0
c.prevent_header = true
end
end
联系人的网格组件:
class OrganisationContacts < Netzke::Basepack::Grid
def configure(c)
super
c.model = "MbContact"
c.columns = [{ :name => :mb_organisation__customer_name,
:header => "Organisation"
}, :cont_salutation, :cont_title, :cont_lastname, :cont_firstname, :cont_email, :cont_tel, :cont_mobile, :cont_birthday]
c.force_fit = true
end
end
该函数this.selectItem(...)
被正确触发并调用 OrganisationMultitab 中的端点。
我有两个问题/疑问
首先 - 如何在选项卡面板中自动重新加载子网格的存储?
链接的谷歌群组文章中描述的方式:https : //groups.google.com/forum/#!searchin/netzke/tabpanel/netzke/PFAQ-wYyNog/2RJgRLzh80oJ 已过时(适用于 netzke v0.5 - 我使用 netzke v0.10.1):
{
:south => {
:item0 => {:load_store_data => aggregatee_instance(:south__item0).get_data},
:item1 => {:load_store_data => aggregatee_instance(:south__item1).get_data}
}
}
第二个问题:我收到一个错误 - 当我手动刷新子网格时:
ActiveModel::ForbiddenAttributesError in NetzkeController#direct
更新
由ActiveModel::ForbiddenAttributesError
我自己解决。netzke-basepack gem 中有一个错误:
Netzke::Basepack::Grid
当组件(如上所述)配置了范围时,在 ActiveModel::ForbiddenAttributesError(rails 4 个强参数)中运行。(config[:scope] 稍后将被合并到作为 ActionController::Parameters 对象的 params 对象。 - 由于范围与数据库相关,这将被拒绝ActiveModel::ForbiddenAttributesError
) 我的解决方案:在endpoint.rb
ActionController::Parameters 中将被转换为一个哈希 - 然后错误就消失了。
我在 github 中为这个 gem 做了一个 fork 和一个 pull request。
但
第二个问题没有解决。
第二个问题:现在可以手动刷新子网格而不会出错,但它们始终为空。
我猜子组件中的范围
component :organisation_contacts do |c|
c.data_store = {auto_load: false}
c.scope = {:mb_organisation_id => component_session[:selected_item_id]}
c. strong_default_attrs = {:mb_organisation_id => component_session[:selected_item_id]}
end
无法访问的值
component_session[:selected_item_id]
组织 MultiTab 父组件?
但有必要拆分组件 - 如此处所述:https ://groups.google.com/forum/#!searchin/netzke/tabpanel/netzke/sDrU7NZIlqg/-2wGmed7fjcJ
希望有人可以帮助我。:-)
谢谢
此致