我在EditorGridPanel中有一列的editor用的是ComoBox,在运行的时候大部分能正常显示,但有时不能正常显示,显示为comobox中的配置项 valueNotFoundText的值。刷新后有时能正常。请问这是为什么?
代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="zrcgl.aspx.cs" Inherits="zrcgl_zrcgl" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>责任区管理</title>
<link href="../extjs/resources/css/ext-all.css" type="text/css" rel="Stylesheet" />
<script src="../extjs/adapter/ext/ext-base.js" type="text/javascript"></script>
<script src="../extjs/ext-all.js" type="text/javascript"></script>
<script src="../extjs/src/locale/ext-lang-zh_CN.js" type="text/javascript"></script>
<script type="text/javascript">
Ext.BLANK_IMAGE_URL = '../extjs/resources/images/default/s.gif';
Ext.QuickTips.init();
</script>
</head>
<body>
<script type ="text/javascript">
var selRecordIndex;
var xcation='update';
var zrcglHttp = new Ext.data.HttpProxy({
url: 'zrcgl_c.aspx'
});
var dmpHttp = new Ext.data.HttpProxy({
url: 'dmp.aspx'
});
var zrcFields = [
{ name: 'id', mapping: 'id' },
{ name: 'zrcmc', mapping: 'zrcmc' },
{ name: 'dmpid', mapping: 'dmpid' },
{ name: 'dmpname', mapping: 'dmpname' },
{ name: 'bz', mapping: 'bz' }
];
/*dmpFields 科室字段
*/
var dmpFields = [
{ name: 'dmpid', mapping: 'dmpid' },
{ name: 'dmpname', mapping: 'dmpname' }
];
var rec_modle = new Ext.data.Record.create([
'id','zrcmc','dmpid','dmpname','bz'
]);
/*dmpStore 是科室数据集
*/
var dmpStore = new Ext.data.JsonStore({
proxy: dmpHttp,
storeId: 'dmpstore',
root: 'records',
totalProperty: 'totalcount',
remoteStore: false,
fields: dmpFields,
idProperty: 'dmpid'
});
/*zrcJsonStore 是主数据集
*/
var zrcJsonStore = new Ext.data.JsonStore({
proxy:zrcglHttp,
storeId:'zrcglstore',
root: 'records',
totalProperty: 'totalcount',
remoteStore: false,
fields:zrcFields,
idProperty:'id'
});
/* onInsert 用来新增记录的
*/
var onInsert = function() {
xcation = 'insert';
var btn = Ext.getCmp('btIns');
btn.disabled = true;
zrcgridpanel.getStore().insert(zrcgridpanel.getStore().getCount(),
new rec_modle({ id: Ext.id(), zrcmc: '', dmpid: '', dmpnme: '', bz: '1' }));
zrcgridpanel.startEditing(zrcgridpanel.getStore().getCount() - 1, 3);
};
/*fxgmc 用来选择记录后,进行修改
*/
var fxgmc = function() {
var selRecord = zrcgridpanel.getSelectionModel().getSelected();
if (selRecord == null) {
Ext.Msg.alert('错误', '请选择要修改的记录');
return false;
}
else {
zrcgridpanel.startEditing(selRecordIndex,3);
}
};
/*onSave 用来保存修改后的记录
*/
var onSave = function() {
var modified = zrcJsonStore.getModifiedRecords({
// newRecordId: Ext.id()
});
Ext.getCmp('btIns').disabled = false;
if (modified.length > 0) {
var recordsToSend = [];
Ext.each(modified, function(record) {
recordsToSend.push(record.data);
});
var grid = Ext.getCmp('zrcEditGrid');
grid.el.mask('Updating', 'x-mask-loading');
grid.stopEditing();
recordsToSend = Ext.encode(recordsToSend);
Ext.Ajax.request({
url: 'zrcgl_c.aspx',
params: {
records: recordsToSend,
query: xcation
},
failure: function(response) {
xcation = 'update';
grid.el.unmask();
zrcJsonStore.rejectChanges();
Ext.Msg.show({
title: '错误',
msg: '数据保存错误',
buttons: Ext.Msg.OK,
icon: Ext.MessageBox.ERROR
});
},
success: function(response) {
if (xcation == "insert") {
var result = Ext.decode(response.responseText);
var record = zrcJsonStore.getAt(zrcJsonStore.getCount() - 1);
var id = result.zrcid;
zrcJsonStore.getAt(zrcJsonStore.getCount() - 1).set('id', result.zrcid);
}
xcation = 'update';
grid.el.unmask();
zrcJsonStore.commitChanges();
var x = selRecordIndex;
var y = zrcgridpanel.getStore().getCount();
var z = zrcJsonStore.getCount();
var ii = 0;
// Ext.each(result.records, function(o) {
// var rIndex = remoteJsonStore.find('newRecordId', o.newRecordId);
// var record = remoteJsonStore.getAt(rIndex);
//
// /record.set('id', o.id);
// delete record.data.newRecordId;
// })
}
});
}
}
var barTool = ['-', {
text: '修改名称',
handler: fxgmc
},
'-', { text: '保存',
handler: onSave
}, '-', {
text: ' 新增',
id: 'btIns',
handler: onInsert
}, '-', {
text: '刷新',
id: 'btFsl',
handler: function() {
zrcJsonStore.reload();
}
}, '-'
];
var dmpeditor = {
xtype: 'combo',
typeAhead: true,
triggerAction: 'all',
forceSelection: true,
selectOnFocus: true,
lazyRender: true,
mode: 'local',
valueNotFoundText: '选择科室',
displayField: 'dmpname',
valueField: 'dmpid',
store: dmpStore
}
var zrcsm = new Ext.grid.CheckboxSelectionModel({
singleSelect: true,
listeners: {
rowselect: function(sm, rowIndex, record) {
selRecordIndex = rowIndex;
}
}
});
Ext.util.Format.comboRenderer = function(dmpeditor) {
return function(value) {
var record = dmpeditor.findRecord(dmpeditor.valueField || dmpeditor.displayField, value);
return record ? record.get(dmpeditor.displayField) : dmpeditor.valueNotFoundText;
}
}
Ext.grid.ComboColumn = Ext.extend(Ext.grid.Column, {
constructor: function(cfg) {
Ext.grid.ComboColumn.superclass.constructor.call(this, cfg);
this.renderer = Ext.util.Format.comboRenderer(this.editor.field ? this.editor.field : this.editor);
}
});
// apply the custom column type to the prototype
Ext.apply(Ext.grid.Column.types, {
combocolumn: Ext.grid.ComboColumn
});
var zrccolunmModel =new Ext.grid.ColumnModel( [
zrcsm,
new Ext.grid.RowNumberer({ header: "序号", width: 50 }),
{
header: '编号',
dataIndex: 'id',
sortable: false,
hidden: true,
menuDisabled: true,
width:50
},
{
header: '责任区名称',
dataIndex: 'zrcmc',
sortable: true,
menuDisabled: true,
id: 'zrcid',
editor:new Ext.form.TextField({allowBlank:false})
},
{
xtype: 'combocolumn',
header: '所属科室',
dataIndex: 'dmpid',
sortable: true,
hidden: false,
editor: dmpeditor,
menuDisabled: true
// renderer: Ext.util.Format.comboRenderer(dmpeditor)
},
{
header: '科室名称',
dataIndex: 'dmpname',
sortable: true,
hidden: true,
editor: dmpeditor,
menuDisabled: true
},
{
header: '标志',
dataIndex: 'bz',
hidden: true,
menuDisabled: true
}
]);
// zrcJsonStore.load({ params: { query: 'init'} });
dmpStore.load({ params: { query: 'initdmp'} });
var zrcgridpanel = new Ext.grid.EditorGridPanel({
title: '责任管理',
renderTo: Ext.getBody(),
id:'zrcEditGrid',
width: 500,
autoHeight: true,
bbar:barTool,
store: zrcJsonStore,
cm: zrccolunmModel,
sm:zrcsm,
autoExpandColumn: 'zrcid'
});
zrcJsonStore.load({ params: { query: 'init'} });
// dmpStore.load({ params: { query: 'initdmp'} });
</script>
</body>
</html>