Extjs EditorGridPanel中ComboBox列的顯示問題
更新時間:2011年07月04日 23:36:52 作者:
EditorGridPanel中嵌入ComboBox通常不會正常顯示ComboBox的store中本想顯示字段,而是顯示的EditorGridPanel中 store的dataindex指定的字段內(nèi)容。
為了解決這個問題需要在EditorGridPanel的ColumnModel中顯示ComboBox的地方使用renderer屬性,重新渲染,方法如下:
//部門列表
var comboxDepartmentStore = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: "GetDepartmentJson.aspx",
method: 'GET'
}),
reader: new Ext.data.JsonReader({
root: 'data',
totalProperty: 'totalCount',
fields: [
{ name: 'departmentid', mapping: 'ID' },
{ name: 'departmentname', mapping: 'Name' }
]
})
});
//根據(jù)Combobox列表中對應(yīng)的Id的值來渲染
function rendererMeterTypeCombobox(value, p, r) {
var index = comboxDepartmentStore.find(Ext.getCmp('cbdepartment').valueField, value);
var record = comboxDepartmentStore.getAt(index);
var displayText = "";
if (record == null) {
return value;
} else {
return record.data.astype; // 獲取record中的數(shù)據(jù)集中的display字段的值
}
}
var sm = new Ext.grid.CheckboxSelectionModel();
var cm = new Ext.grid.ColumnModel({
columns: [sm, new Ext.grid.RowNumberer(), {
header: 'id',
dataIndex: 'id',
hidden: true
}, {
header: '姓名',
width: 40,
dataIndex: 'name'
}, {
header: '所屬部門',
width: 80,
dataIndex: 'department',
renderer: rendererDepartmentCombobox,
editor: new Ext.form.ComboBox({
id: "cbdepartment", //必須有
forceSelection: true,
selectOnFocus: true,
typeAhead: true,
triggerAction: 'all',
store: comboxDepartmentStore,
mode: 'local',
displayField: 'departmentname',
valueField: 'departmentid',
lazyRender: true
})
}],
defaults: {
zsortable: true,
menuDisabled: false,
width: 100
}
});
var editGrid = new Ext.grid.EditorGridPanel({
id: 'TestGrid',
store: store, //EditorGridPanel使用的store
trackMouseOver: true,
disableSelection: false,
clicksToEdit: 1, //設(shè)置點擊幾次才可編輯
loadMask: true,
autoHeight: true,
cm: cm,
sm: sm,
viewConfig: {
columnsText: '顯示/隱藏列',
sortAscText: '正序排列',
sortDescText: '倒序排列',
forceFit: true,
enableRowBody: true
},
bbar: new Ext.PagingToolbar({
pageSize: 25,
store: store,
displayInfo: true,
displayMsg: '當(dāng)前顯示從{0}至{1}, 共{2}條記錄',
emptyMsg: "當(dāng)前沒有記錄"
})
});
復(fù)制代碼 代碼如下:
//部門列表
var comboxDepartmentStore = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: "GetDepartmentJson.aspx",
method: 'GET'
}),
reader: new Ext.data.JsonReader({
root: 'data',
totalProperty: 'totalCount',
fields: [
{ name: 'departmentid', mapping: 'ID' },
{ name: 'departmentname', mapping: 'Name' }
]
})
});
//根據(jù)Combobox列表中對應(yīng)的Id的值來渲染
function rendererMeterTypeCombobox(value, p, r) {
var index = comboxDepartmentStore.find(Ext.getCmp('cbdepartment').valueField, value);
var record = comboxDepartmentStore.getAt(index);
var displayText = "";
if (record == null) {
return value;
} else {
return record.data.astype; // 獲取record中的數(shù)據(jù)集中的display字段的值
}
}
var sm = new Ext.grid.CheckboxSelectionModel();
var cm = new Ext.grid.ColumnModel({
columns: [sm, new Ext.grid.RowNumberer(), {
header: 'id',
dataIndex: 'id',
hidden: true
}, {
header: '姓名',
width: 40,
dataIndex: 'name'
}, {
header: '所屬部門',
width: 80,
dataIndex: 'department',
renderer: rendererDepartmentCombobox,
editor: new Ext.form.ComboBox({
id: "cbdepartment", //必須有
forceSelection: true,
selectOnFocus: true,
typeAhead: true,
triggerAction: 'all',
store: comboxDepartmentStore,
mode: 'local',
displayField: 'departmentname',
valueField: 'departmentid',
lazyRender: true
})
}],
defaults: {
zsortable: true,
menuDisabled: false,
width: 100
}
});
var editGrid = new Ext.grid.EditorGridPanel({
id: 'TestGrid',
store: store, //EditorGridPanel使用的store
trackMouseOver: true,
disableSelection: false,
clicksToEdit: 1, //設(shè)置點擊幾次才可編輯
loadMask: true,
autoHeight: true,
cm: cm,
sm: sm,
viewConfig: {
columnsText: '顯示/隱藏列',
sortAscText: '正序排列',
sortDescText: '倒序排列',
forceFit: true,
enableRowBody: true
},
bbar: new Ext.PagingToolbar({
pageSize: 25,
store: store,
displayInfo: true,
displayMsg: '當(dāng)前顯示從{0}至{1}, 共{2}條記錄',
emptyMsg: "當(dāng)前沒有記錄"
})
});
您可能感興趣的文章:
- Extjs4.0 ComboBox如何實現(xiàn)三級聯(lián)動
- ExtJS4給Combobox設(shè)置列表中的默認值示例
- Extjs中ComboBoxTree實現(xiàn)的下拉框樹效果(自寫)
- extjs3 combobox取value和text案例詳解
- Extjs中ComboBox加載并賦初值的實現(xiàn)方法
- extjs中g(shù)rid中嵌入動態(tài)combobox的應(yīng)用
- ExtJS PropertyGrid中使用Combobox選擇值問題
- ExtJs使用總結(jié)(非常詳細)
- ExtJS 學(xué)習(xí)專題(一) 如何應(yīng)用ExtJS(附實例)
- Extjs讓combobox寫起來簡潔又漂亮
相關(guān)文章
關(guān)于extjs treepanel復(fù)選框選中父節(jié)點與子節(jié)點的問題
實現(xiàn)帶有復(fù)選框的樹,選中父節(jié)點時,選中所有子節(jié)點。取消所有子節(jié)點時,才能取消根節(jié)點,感興趣的朋友可以了解下本文2013-04-04
ext combox 下拉框不出現(xiàn)自動提示,自動選中的解決方法
ext combox 如果想實現(xiàn)類似于 baidu 搜索時的提示功能。必須禁止其分頁功能才可以。2010-02-02
解決Extjs4中form表單提交后無法進入success函數(shù)問題
form表單提交后無法進入success函數(shù)的問題,很是常見,下面有個不錯的解決方法,感興趣的朋友可以參考下2013-11-11
Extjs學(xué)習(xí)筆記之一 初識Extjs之MessageBox
去官網(wǎng)下載好extjs的壓縮包,解壓縮之后得到如下目錄結(jié)構(gòu)。2010-01-01

