ExtJS 如何在网格面板中构建联动组合框
ExtJS how to build linkage comboboxes in Grid panel
我是 ExtJS 的新手,我正在开发一个地址簿,管理员可以在其中通过从两个组合框中选择列出的州和城市来编辑用户的地址。
我需要在网格面板中构建一些联动组合框,以便管理员在第一个下拉列表中选择一个州后,相关城市将自动列在第二个下拉列表中。
如果它只是一个简单的面板,我可以在使用以下代码选择状态后更新 cityStore:
{
xtype:"combo",
name:'state',
id:'state',
displayField:'name',
valueField:'id',
store:storeState,
triggerAction:'all',
queryMode:'local',
selecOnFocus:true,
forceSelection:true,
allowBlank:false,
editable:true,
//using select listener for updating city store
listeners:{
select:function(combo,record,index){
try{
var city = Ext.getCmp('city');
city.clearValue();
city.store.load(
{
params:{
paramId:combo.getValue()
}
}
);
}catch(ex){
alert("Failed to load data");
}
}
}
},
但是在 GridPanel 中,如果我用同样的方式更新 cityStore,整个列都会改变。
无论如何只能解决网格面板中同一行中的列?谢谢!
每次用户点击城市编辑器时,您只需要使用来自 State 的参数重新加载 Cities 商店。在组合框的 beforequery 事件中执行。
{
//this is your Cities combo
xtype: 'combo',
valueField: 'foo',
displayField: 'bar',
queryMode: 'remote',
queryCaching: false, //don't forget to disable query caching
bind: {
store: '{cities}',
},
listeners: {
beforequery: function(queryPlan) {
//get param from your States store
queryPlan.combo.getStore();
//then load this store
}
}
}
您需要使用 validateedit
& beforeedit
网格事件来更新城市商店。
listeners: {
validateedit: { // to check if state value is changed & clearing city value
fn: function(event,editor){
switch (editor.field) {
case 'state':
if(editor.value!=editor.record.getData().state)
editor.record.set('city',null);
break;
}
return true;
}
},
beforeedit: { // to update the city store based the state value of corresponding row
fn: function(event,editor){
switch (editor.field) {
case 'city':
var cityStore = Ext.data.StoreManager.lookup('cityStore');
cityStore.load({
params:{
paramId:editor.value
}
});
break;
}
return true;
}
}
}
Here 是一个工作示例,我在其中使用州和城市的两个本地商店。每当使用相同 row.There 中给出的状态值编辑城市商店时,过滤城市商店是三个状态 A、B、C,分别具有 1-5、6-10 和 11-15 个城市。
我是 ExtJS 的新手,我正在开发一个地址簿,管理员可以在其中通过从两个组合框中选择列出的州和城市来编辑用户的地址。
我需要在网格面板中构建一些联动组合框,以便管理员在第一个下拉列表中选择一个州后,相关城市将自动列在第二个下拉列表中。
如果它只是一个简单的面板,我可以在使用以下代码选择状态后更新 cityStore:
{
xtype:"combo",
name:'state',
id:'state',
displayField:'name',
valueField:'id',
store:storeState,
triggerAction:'all',
queryMode:'local',
selecOnFocus:true,
forceSelection:true,
allowBlank:false,
editable:true,
//using select listener for updating city store
listeners:{
select:function(combo,record,index){
try{
var city = Ext.getCmp('city');
city.clearValue();
city.store.load(
{
params:{
paramId:combo.getValue()
}
}
);
}catch(ex){
alert("Failed to load data");
}
}
}
},
但是在 GridPanel 中,如果我用同样的方式更新 cityStore,整个列都会改变。 无论如何只能解决网格面板中同一行中的列?谢谢!
每次用户点击城市编辑器时,您只需要使用来自 State 的参数重新加载 Cities 商店。在组合框的 beforequery 事件中执行。
{
//this is your Cities combo
xtype: 'combo',
valueField: 'foo',
displayField: 'bar',
queryMode: 'remote',
queryCaching: false, //don't forget to disable query caching
bind: {
store: '{cities}',
},
listeners: {
beforequery: function(queryPlan) {
//get param from your States store
queryPlan.combo.getStore();
//then load this store
}
}
}
您需要使用 validateedit
& beforeedit
网格事件来更新城市商店。
listeners: {
validateedit: { // to check if state value is changed & clearing city value
fn: function(event,editor){
switch (editor.field) {
case 'state':
if(editor.value!=editor.record.getData().state)
editor.record.set('city',null);
break;
}
return true;
}
},
beforeedit: { // to update the city store based the state value of corresponding row
fn: function(event,editor){
switch (editor.field) {
case 'city':
var cityStore = Ext.data.StoreManager.lookup('cityStore');
cityStore.load({
params:{
paramId:editor.value
}
});
break;
}
return true;
}
}
}
Here 是一个工作示例,我在其中使用州和城市的两个本地商店。每当使用相同 row.There 中给出的状态值编辑城市商店时,过滤城市商店是三个状态 A、B、C,分别具有 1-5、6-10 和 11-15 个城市。