[英]How to create cell editor for speciall cell in grid with another grid and selection of value from it in ExtJs?
[英]How define differents stores for each cell combobox editor in a grid?
我需要使用extjs 4.2.1實現一個網格。 這個網格將有cellEditing插件,在列中我將有許多文本字段和組合框。
我的問題是針對特定情況。 我有一個國家專欄(例如)。 列編輯器將與國家商店組合使用。 下一個組合框將是同一行指數所選國家的城市。 當我定義該商店時,此列將保留在同一商店,我不知道這一點。
在第0行,我選擇美國,我必須在下一個組合中加載美國城市。 在第1行,我選擇英國國家,我必須加載英國城市,但如果回到第0行並選擇美國城市,我想看到美國城市,而不是英國城市。
如何為每個組合單元定義不同的存儲?
您需要使用Ext.grid.plugin.CellEditing
插件設置網格,以啟用網格單元格編輯。 作為城市列編輯器,您將使用Ext.form.field.ComboBox
。 當用戶在城市列中的單元格上進入編輯模式時,您將過濾編輯器組合框的商店。 有關篩選從編輯行記錄中獲得的城市組合框所需的所選國家/地區的信息。
首先,您必須使用Ext.form.field.ComboBox
實例設置城市列編輯器,該實例將用於編輯:
var comboCities = Ext.create('Ext.form.field.ComboBox', { store: storeCities, queryMode: 'local', displayField: 'name', valueField: 'name' });
並在網格列中定義:
columns: [ ... { header: 'City', dataIndex: 'city', editor: comboCities, }, ... ]
其次,您必須為beforeedit
事件添加到Ext.grid.plugin.CellEditing
插件配置偵聽beforeedit
中。 在此偵聽器中,您可以確定哪個列開始編輯。 如果編輯列是城市列,則可以從編輯有關所選國家/地區的行記錄信息和過濾器comboCities
商店獲取。 因此,在過濾商店中,只有選定國家/地區的城市。
例如,網格配置中的插件配置應該是:
{ ... plugins: [ Ext.create('Ext.grid.plugin.CellEditing', { clicksToEdit: 1, listeners: { beforeedit: function(editor, e) { // detrmine which column start editing if (e.colIdx == 2) { // get information about selected country from editin row record var selectedCountry = e.record.get('country'); // filter store with cities storeCities.clearFilter(); storeCities.filter('country', selectedCountry); } } } }) ], ... }
通過配置示例查看實時小提琴: https : //fiddle.sencha.com/#fiddle/2bj
你必須定義你的商店一次
Ext.define('MyApp.city.Store',{
extend:'Ext.data.Store',
//all properties which you need
});
你應該為城市單元格創建它的實例
cityStore = Ext.create('MyApp.city.Store');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.