Ext中combobox在Grid里显示问题

Ext的Grid中使用combobox做为编辑控件时,遇到在combobox中选择了相应的选项时(displayField),在grid中却显示了valueField值。现解决如下:

图示:

Ext中combobox在Grid里显示问题插图

js代码:

Ext中combobox在Grid里显示问题插图1

  1 Ext中combobox在Grid里显示问题插图2      var  grid;
  2 Ext中combobox在Grid里显示问题插图2      function  ready(queryCondition)
  3 Ext中combobox在Grid里显示问题插图3      {
  4 Ext中combobox在Grid里显示问题插图4          var  pageSize  =   150 ;
  5 Ext中combobox在Grid里显示问题插图4          var  queryConditionTemplate  =  document.getElementById( hid ).value;
  6 Ext中combobox在Grid里显示问题插图4          var  url  =   ../AjaxFactory/AjaxGridData.aspx?cln=BindCommandTemplate&orderField=FGID&pagesize=   +  pageSize + &orderType=asc&queryConditionTemplate= + queryConditionTemplate;
  7 Ext中combobox在Grid里显示问题插图4         
  8 Ext中combobox在Grid里显示问题插图4          var  url1 =   ../AjaxFactory/AjaxGridData.aspx?cln1=BindTemplateGroup&orderField=DMCOD&orderType=asc&projectID= + fatherID;
  9 Ext中combobox在Grid里显示问题插图4          var  url2  =   ../AjaxFactory/AjaxGridData.aspx?cln2=BindG050&orderField=DMCOD&orderType=asc ;
 10 Ext中combobox在Grid里显示问题插图4          // var store;
 11 Ext中combobox在Grid里显示问题插图4          var  comStore1;
 12 Ext中combobox在Grid里显示问题插图4          var  comStore2;
 13 Ext中combobox在Grid里显示问题插图4          var  storeMapping;
 14 Ext中combobox在Grid里显示问题插图4          var  addCategory;
 15 Ext中combobox在Grid里显示问题插图4          var  afterEdit;
 16 Ext中combobox在Grid里显示问题插图4          var  defaultStore;
 17 Ext中combobox在Grid里显示问题插图4          var  specoalStore;
 18 Ext中combobox在Grid里显示问题插图4        
 19 Ext中combobox在Grid里显示问题插图4         storeMapping = [ FGID , COMMANDID , PARENTNAME , FUNCTIONIDNAME , NAME , GROUPNAME , HANDLESNAME ];
 20 Ext中combobox在Grid里显示问题插图4         
 21 Ext中combobox在Grid里显示问题插图4          // grid 数据源
 22 Ext中combobox在Grid里显示问题插图5         store  =   new  Ext.data.Store( {
 23 Ext中combobox在Grid里显示问题插图5         proxy: new  Ext.data.HttpProxy( {
 24 Ext中combobox在Grid里显示问题插图4             url:url
 25 Ext中combobox在Grid里显示问题插图6         }
),
 26 Ext中combobox在Grid里显示问题插图5         reader: new  Ext.data.JsonReader( {
 27 Ext中combobox在Grid里显示问题插图4             root: data ,
 28 Ext中combobox在Grid里显示问题插图4             totalProperty:  totalCount ,
 29 Ext中combobox在Grid里显示问题插图4             fields:
 30 Ext中combobox在Grid里显示问题插图4             [
 31 Ext中combobox在Grid里显示问题插图4                  FGID , COMMANDID , PARENTNAME , SONNAME , NAME , FUNCTIONID , GROUPNAME , HANDLESNAME
 32 Ext中combobox在Grid里显示问题插图4             ]
 33 Ext中combobox在Grid里显示问题插图6         }
),    
 34 Ext中combobox在Grid里显示问题插图4         remoteSort: true
 35 Ext中combobox在Grid里显示问题插图6         }
);    
 36 Ext中combobox在Grid里显示问题插图4          // 模板组
 37 Ext中combobox在Grid里显示问题插图5         comStore1  =   new  Ext.data.Store( {
 38 Ext中combobox在Grid里显示问题插图5                         proxy: new  Ext.data.HttpProxy( {url:url1} ),
 39 Ext中combobox在Grid里显示问题插图5                         reader:  new  Ext.data.JsonReader( {
 40 Ext中combobox在Grid里显示问题插图4                         root: data ,
 41 Ext中combobox在Grid里显示问题插图4                         totalProperty:  totalCount ,
 42 Ext中combobox在Grid里显示问题插图4                         fields:
 43 Ext中combobox在Grid里显示问题插图4                         [ GROUPID , GROUP_NAME ]
 44 Ext中combobox在Grid里显示问题插图6                         }
)
 45 Ext中combobox在Grid里显示问题插图6                     }
),
 46 Ext中combobox在Grid里显示问题插图4         comStore1.load();
 47 Ext中combobox在Grid里显示问题插图4          // 读写
 48 Ext中combobox在Grid里显示问题插图5         comStore2  =   new  Ext.data.Store( {
 49 Ext中combobox在Grid里显示问题插图5                         proxy: new  Ext.data.HttpProxy( {url:url2} ),
 50 Ext中combobox在Grid里显示问题插图5                         reader:  new  Ext.data.JsonReader( {            
 51 Ext中combobox在Grid里显示问题插图4                         root: data ,
 52 Ext中combobox在Grid里显示问题插图4                         totalProperty:  totalCount ,
 53 Ext中combobox在Grid里显示问题插图4                         fields:
 54 Ext中combobox在Grid里显示问题插图4                         [ DMCOD , DMCPT ]
 55 Ext中combobox在Grid里显示问题插图6                         }
)
 56 Ext中combobox在Grid里显示问题插图6                     }
),
 57 Ext中combobox在Grid里显示问题插图4             comStore2.load();
 58 Ext中combobox在Grid里显示问题插图4         
 59 Ext中combobox在Grid里显示问题插图4        
 60 Ext中combobox在Grid里显示问题插图4          var  cm = new  Ext.grid.ColumnModel([        
 61 Ext中combobox在Grid里显示问题插图4          new  Ext.grid.RowNumberer(),
 62 Ext中combobox在Grid里显示问题插图5          {header: 角色编号 ,align: center ,sortable:  false ,dataIndex: FGID ,hidden: true } ,
 63 Ext中combobox在Grid里显示问题插图5          {header: 命令编号 ,align: center ,sortable:  false ,dataIndex: COMMANDID ,hidden: true } ,
 64 Ext中combobox在Grid里显示问题插图5          {header: 子系统 ,align: center ,sortable:  false ,dataIndex: PARENTNAME } ,
 65 Ext中combobox在Grid里显示问题插图5          {header: 模块 ,align: center ,sortable:  false ,dataIndex: SONNAME } ,
 66 Ext中combobox在Grid里显示问题插图5          {header: 功能 ,align: center ,sortable:  false ,dataIndex: NAME } ,
 67 Ext中combobox在Grid里显示问题插图5          {
 68 Ext中combobox在Grid里显示问题插图4                 header: 模板组 ,
 69 Ext中combobox在Grid里显示问题插图4                 dataIndex: GROUPNAME ,
 70 Ext中combobox在Grid里显示问题插图4                 align: center ,
 71 Ext中combobox在Grid里显示问题插图5                 editor: new  Ext.form.ComboBox( {
 72 Ext中combobox在Grid里显示问题插图4                     id: termtype ,
 73 Ext中combobox在Grid里显示问题插图4                     name: termtype ,                    
 74 Ext中combobox在Grid里显示问题插图4                     readOnly: true ,
 75 Ext中combobox在Grid里显示问题插图4                     fieldLabel:  模板组 ,    
 76 Ext中combobox在Grid里显示问题插图4                     hiddenName: id ,
 77 Ext中combobox在Grid里显示问题插图4                     store: comStore1,
 78 Ext中combobox在Grid里显示问题插图4                     displayField: GROUP_NAME ,
 79 Ext中combobox在Grid里显示问题插图4                     valueField: GROUPID ,                    
 80 Ext中combobox在Grid里显示问题插图4                     typeAhead:  true ,
 81 Ext中combobox在Grid里显示问题插图4                     mode:  local ,
 82 Ext中combobox在Grid里显示问题插图4                     triggerAction:  all ,
 83 Ext中combobox在Grid里显示问题插图4                     emptyText: 请选择 ,
 84 Ext中combobox在Grid里显示问题插图4                     selectOnFocus: true
 85 Ext中combobox在Grid里显示问题插图6                     }
),
 86 Ext中combobox在Grid里显示问题插图4                     renderer:  function (value, cellmeta, record) 
 87 Ext中combobox在Grid里显示问题插图5                      {
 88 Ext中combobox在Grid里显示问题插图4                          // 通过匹配value取得ds索引
 89 Ext中combobox在Grid里显示问题插图4                          var  index  =  comStore1.find(Ext.getCmp( termtype ).valueField,value);
 90 Ext中combobox在Grid里显示问题插图4                          // 通过索引取得记录ds中的记录集
 91 Ext中combobox在Grid里显示问题插图4                          var  record  =  comStore1.getAt(index);
 92 Ext中combobox在Grid里显示问题插图4                          // 返回记录集中的value字段的值
 93 Ext中combobox在Grid里显示问题插图4                          var  returnvalue  =   “” ;
 94 Ext中combobox在Grid里显示问题插图4                          if  (record) 
 95 Ext中combobox在Grid里显示问题插图5                          {
 96 Ext中combobox在Grid里显示问题插图4                             returnvalue  =  record.data.GROUP_NAME;
 97 Ext中combobox在Grid里显示问题插图6                         }

 98 Ext中combobox在Grid里显示问题插图4                          return  returnvalue; // 注意这个地方的value是上面displayField中的value
 99 Ext中combobox在Grid里显示问题插图6                      }

100 Ext中combobox在Grid里显示问题插图6             }
,
101 Ext中combobox在Grid里显示问题插图5              {
102 Ext中combobox在Grid里显示问题插图4                 header: 操作性 ,
103 Ext中combobox在Grid里显示问题插图4                 dataIndex: HANDLESNAME ,
104 Ext中combobox在Grid里显示问题插图4                 align: center ,
105 Ext中combobox在Grid里显示问题插图5                 editor: new  Ext.form.ComboBox( {
106 Ext中combobox在Grid里显示问题插图4                     id: termtype1 ,
107 Ext中combobox在Grid里显示问题插图4                     name: termtype1 ,
108 Ext中combobox在Grid里显示问题插图4                     readOnly: true ,                    
109 Ext中combobox在Grid里显示问题插图4                     fieldLabel:  操作性 ,
110 Ext中combobox在Grid里显示问题插图4                     hiddenName: id ,
111 Ext中combobox在Grid里显示问题插图4                     store: comStore2,
112 Ext中combobox在Grid里显示问题插图4                     displayField: DMCPT ,
113 Ext中combobox在Grid里显示问题插图4                     valueField: DMCOD ,
114 Ext中combobox在Grid里显示问题插图4                     
115 Ext中combobox在Grid里显示问题插图4                     typeAhead:  true ,
116 Ext中combobox在Grid里显示问题插图4                     mode:  remote ,
117 Ext中combobox在Grid里显示问题插图4                     triggerAction:  all ,
118 Ext中combobox在Grid里显示问题插图4                     emptyText: 请选择 ,
119 Ext中combobox在Grid里显示问题插图4                     selectOnFocus: true
120 Ext中combobox在Grid里显示问题插图6                 }
),
121 Ext中combobox在Grid里显示问题插图4                     renderer:  function (value, cellmeta, record) 
122 Ext中combobox在Grid里显示问题插图5                      {
123 Ext中combobox在Grid里显示问题插图4                          // 通过匹配value取得ds索引
124 Ext中combobox在Grid里显示问题插图4                          var  index  =  comStore2.find(Ext.getCmp( termtype1 ).valueField,value);
125 Ext中combobox在Grid里显示问题插图4                          // 通过索引取得记录ds中的记录集
126 Ext中combobox在Grid里显示问题插图4                          var  record  =  comStore1.getAt(index);
127 Ext中combobox在Grid里显示问题插图4                          // 返回记录集中的value字段的值
128 Ext中combobox在Grid里显示问题插图4                          var  returnvalue  =   “” ;
129 Ext中combobox在Grid里显示问题插图4                          if  (record) 
130 Ext中combobox在Grid里显示问题插图5                          {
131 Ext中combobox在Grid里显示问题插图4                             returnvalue  =  record.data.DMCPT;
132 Ext中combobox在Grid里显示问题插图6                         }

133 Ext中combobox在Grid里显示问题插图4                          return  returnvalue; // 注意这个地方的value是上面displayField中的value
134 Ext中combobox在Grid里显示问题插图6                      }

135 Ext中combobox在Grid里显示问题插图6             }

136 Ext中combobox在Grid里显示问题插图4         ]);    
137 Ext中combobox在Grid里显示问题插图4         cm.defaultSortable  =   true ;
138 Ext中combobox在Grid里显示问题插图4         
139 Ext中combobox在Grid里显示问题插图5         grid = new  Ext.grid.EditorGridPanel( {
140 Ext中combobox在Grid里显示问题插图4                 id: topicCategoryGrid ,    
141 Ext中combobox在Grid里显示问题插图4                  store:store,
142 Ext中combobox在Grid里显示问题插图4                   cm:cm, 
143 Ext中combobox在Grid里显示问题插图4                 loadMask:  true ,
144 Ext中combobox在Grid里显示问题插图4                 clicksToEdit: 1 ,
145 Ext中combobox在Grid里显示问题插图4                 renderTo: authorize
146 Ext中combobox在Grid里显示问题插图4                 trackMouseOver: true ,
147 Ext中combobox在Grid里显示问题插图4                 autoShow :  true ,
148 Ext中combobox在Grid里显示问题插图4                 autoScroll:  true ,
149 Ext中combobox在Grid里显示问题插图5                 loadMask: {msg: 数据加载中,请稍等Ext中combobox在Grid里显示问题插图7 } ,
150 Ext中combobox在Grid里显示问题插图4                 frame: true ,
151 Ext中combobox在Grid里显示问题插图4                 height: window.screen.availHeight    200 , // 176,
152 Ext中combobox在Grid里显示问题插图4                 width: window.screen.availWidth   s_widths,
153 Ext中combobox在Grid里显示问题插图5                 viewConfig: {forceFit: true } ,    
154 Ext中combobox在Grid里显示问题插图4                  region: center ,
155 Ext中combobox在Grid里显示问题插图5                  bbar: new  Ext.PagingToolbar( {
156 Ext中combobox在Grid里显示问题插图4                 pageSize: 150 ,
157 Ext中combobox在Grid里显示问题插图4                 store:store,
158 Ext中combobox在Grid里显示问题插图4                 displayInfo: true ,
159 Ext中combobox在Grid里显示问题插图4                 displayMsg: 当前显示 {0} – {1}条记录 /共 {2}条记录 ,
160 Ext中combobox在Grid里显示问题插图4                 emptyMsg: 没有数据
161 Ext中combobox在Grid里显示问题插图6                 }
)
162 Ext中combobox在Grid里显示问题插图6         }
);
163 Ext中combobox在Grid里显示问题插图4         grid.on( afteredit ,
164 Ext中combobox在Grid里显示问题插图4              function  (obj)
165 Ext中combobox在Grid里显示问题插图5              {
166 Ext中combobox在Grid里显示问题插图4                  var  r = obj.record;
167 Ext中combobox在Grid里显示问题插图4                  var  l  =  obj.field;
168 Ext中combobox在Grid里显示问题插图4                  var  uFGID = r.get( FGID );
169 Ext中combobox在Grid里显示问题插图4                  var  uCOMMANDID  =  r.get( COMMANDID );    
170 Ext中combobox在Grid里显示问题插图4                  var  uGROUPNAME  =  Ext.getCmp( termtype ).getValue();
171 Ext中combobox在Grid里显示问题插图4                  var  uHANDLESNAME  =  Ext.getCmp( termtype1 ).getValue();
172 Ext中combobox在Grid里显示问题插图4                  var  today  =   new  Date().getTime();
173 Ext中combobox在Grid里显示问题插图5                 Ext.Ajax.request( {
174 Ext中combobox在Grid里显示问题插图4                 url: ../AjaxFactory/AjaxGridData.aspx?cln=UpdateRoleTemplate&orderField=FGID&orderType=asc&da= + today,
175 Ext中combobox在Grid里显示问题插图4                 method: POST ,
176 Ext中combobox在Grid里显示问题插图5                 params:  {
177 Ext中combobox在Grid里显示问题插图4                     uFGID:uFGID,    
178 Ext中combobox在Grid里显示问题插图4                     uCOMMANDID:uCOMMANDID,
179 Ext中combobox在Grid里显示问题插图4                     uGROUPNAME:uGROUPNAME,
180 Ext中combobox在Grid里显示问题插图4                     uHANDLESNAME:uHANDLESNAME,
181 Ext中combobox在Grid里显示问题插图4                     l:l
182 Ext中combobox在Grid里显示问题插图6                 }
,
183 Ext中combobox在Grid里显示问题插图5                 success: function (response) {
184 Ext中combobox在Grid里显示问题插图4                  // store.load();
185 Ext中combobox在Grid里显示问题插图6                 }
,
186 Ext中combobox在Grid里显示问题插图5                 failure: function (response) {
187 Ext中combobox在Grid里显示问题插图4                 Ext.MessageBox.alert( 温馨提示 请求失败! );
188 Ext中combobox在Grid里显示问题插图6                 }
,
189 Ext中combobox在Grid里显示问题插图4                 scope: this
190 Ext中combobox在Grid里显示问题插图6                 }
);
191 Ext中combobox在Grid里显示问题插图6             }
,
192 Ext中combobox在Grid里显示问题插图4              this );
193 Ext中combobox在Grid里显示问题插图4
194 Ext中combobox在Grid里显示问题插图5             grid.getStore().load( {
195 Ext中combobox在Grid里显示问题插图5             params:  {
196 Ext中combobox在Grid里显示问题插图4                 start:  0 ,
197 Ext中combobox在Grid里显示问题插图4                 limit:  12
198 Ext中combobox在Grid里显示问题插图6             }

199 Ext中combobox在Grid里显示问题插图6         }
);  
200 Ext中combobox在Grid里显示问题插图8     }

201 Ext中combobox在Grid里显示问题插图2          // 自适应
202 Ext中combobox在Grid里显示问题插图2          function  GridOnReSize(s_widths)
203 Ext中combobox在Grid里显示问题插图3          {
204 Ext中combobox在Grid里显示问题插图4             grid.setWidth(window.screen.availWidth   s_widths);    
205 Ext中combobox在Grid里显示问题插图4             grid.setHeight(window.screen.availHeight    200 );
206 Ext中combobox在Grid里显示问题插图8         }
  
207 Ext中combobox在Grid里显示问题插图2     

关键代码如下:

Ext中combobox在Grid里显示问题插图1

 1 Ext中combobox在Grid里显示问题插图2                     renderer:  function (value, cellmeta, record) 
 2 Ext中combobox在Grid里显示问题插图3                      {
 3 Ext中combobox在Grid里显示问题插图4                          // 通过匹配value取得ds索引
 4 Ext中combobox在Grid里显示问题插图4                          var  index  =  comStore1.find(Ext.getCmp( termtype ).valueField,value);
 5 Ext中combobox在Grid里显示问题插图4                          // 通过索引取得记录ds中的记录集
 6 Ext中combobox在Grid里显示问题插图4                          var  record  =  comStore1.getAt(index);
 7 Ext中combobox在Grid里显示问题插图4                          // 返回记录集中的value字段的值
 8 Ext中combobox在Grid里显示问题插图4                          var  returnvalue  =   “” ;
 9 Ext中combobox在Grid里显示问题插图4                          if  (record) 
10 Ext中combobox在Grid里显示问题插图5                          {
11 Ext中combobox在Grid里显示问题插图4                             returnvalue  =  record.data.GROUP_NAME;
12 Ext中combobox在Grid里显示问题插图6                         }

13 Ext中combobox在Grid里显示问题插图4                          return  returnvalue; // 注意这个地方的value是上面displayField中的value
14 Ext中combobox在Grid里显示问题插图8                      }

标签