請問EXT GRID 如何通過rowIndex和columnIndex改變列內容?
2012-01-07 01:10
162 查看
如下拿出行列出來后請問如何根據這個值改變對應單元格的內容?
答:
要改变单元格里的内容最终还是要修改数据源
var record = grid.getStore().getAt(rowIndex); //找到这一行
record.set("dataIndex的值","修改后的值");
例:
grid:
更换值:
function cellclick(grid, rowIndex, columnIndex, e) { var record = grid.getStore().getAt(rowIndex); //Get the Record var fieldName = grid.getColumnModel().getDataIndex(columnIndex); //Get field name var data = record.get(fieldName); Ext.MessageBox.alert("show","当前选中的数据是:"+data + "行:"+rowIndex+"列:"+columnIndex); }
答:
要改变单元格里的内容最终还是要修改数据源
var record = grid.getStore().getAt(rowIndex); //找到这一行
record.set("dataIndex的值","修改后的值");
例:
grid:
this.fields = new Ext.data.Record.create([{ name : 'position' }, { name : 'personnelname' }, { name : 'mobile' }, { name : 'agencyname' }, { name : 'personnel_id' }, { name : 'agencyid' }]); this.store = new Ext.data.Store({ reader : new Ext.data.JsonReader({ fields : panel.fields }) }); function getpositionimage(val) { var src='<img src=images/user.png></img>'; switch(val) { case 9: src='<img src=images/user_red.png></img>'; break; case 1: src='<img src=images/user.png></img>'; break; default: src='<img src=images/user.png></img>'; } return src; } this.cm = new Ext.grid.ColumnModel([panel.sm, { id : 'position', dataIndex : 'position', header : '职位', renderer : getpositionimage, width : 30 }, { id : 'personnelname', dataIndex : 'personnelname', header : '工号-姓名', width : 120 }, { id : 'mobile', dataIndex : 'mobile', header : '联系电话', width : 80 }, { id : 'agencyname', dataIndex : 'agencyname', header : '单位名称' }, { id : 'personnel_id', dataIndex : 'personnel_id', header : '人员ID', hidden : true }, { id : 'agencyid', dataIndex : 'agencyid', header : '机构ID', hidden : true }]); this.carListGrid = new Ext.grid.GridPanel({ id : 'searchTab', layout : 'fit', title : '查询结果', autoScroll : true, trackMouseOver : true, border : false, sm : panel.sm, cm : panel.cm, store : panel.store, listeners : { 'cellcontextmenu' : function(grid, row, cell, e) { //grid.getSelectionModel().selectRow(row, true); selRow = grid.getStore().getAt(row);/* grid.getSelectionModel().fireEvent('rowselect', grid.getSelectionModel(), row, grid.getStore().getAt(row));*/ nodeid = -selRow.get('agencyid'); id = selRow.get('personnel_id'); if (id > 0) { c = panel.contextMenu; c.showAt(e.getXY()); } e.preventDefault(); e.stopPropagation(); return false; }, 'contextmenu' : function(e) { e.preventDefault(); return false; }, 'rowdblclick' : function(grid) { selRow = grid.getSelectionModel().getSelected(); nodeid = -selRow.get('agencyid'); id = selRow.get('personnel_id'); panel.editPersonnel(); /* curSelUnitId = []; curSelCalls = []; selCallsHash.clear(); curSelNumberPlates = []; curSelNumberPlates.push(row.get('number_plate')); curSelUnitId.push(row.get('unitid')); curSelCalls.push(row.get('callletter')); selCallsHash.push(row.get('callletter'), row .get('unitid'));*/ } } });
更换值:
formPanel.getForm().submit({ waitTitle : '请稍候', waitMsg : '正在提交表单数据,请稍候.......', url : 'servlet/UserServlet', method : 'post', params : { type : 'updateUserPersonnel' }, success : function(f, action) { Ext.Msg.alert('提示!', '修改成功!'); if (panel.personnel_position.getValue() == 9) { personnelNode.setIcon('images/user_red.png'); } var activetab=panel.treetabpanel.getActiveTab(); if(activetab.id!='searchTab'){ personnelNode.setText(panel.personnelcode .getValue() + '-' + panel.personnelname.getValue()); }else{//下面两句是实用实例,本来计划标为红色,结果好象这个编辑器解析不出来 selRow.set('personnelname',panel.personnelcode.getValue()+'-'+panel.personnelname.getValue()); selRow.set('mobile',panel.mobile.getValue()); } }, failure : function(f, action) { switch (action.failureType) { case Ext.form.Action.CLIENT_INVALID : Ext.Msg.alert('错误!', '存在未通过验证的数据!'); break; case Ext.form.Action.CONNECT_FAILURE : Ext.Msg.alert('错误!', '连接错误!'); break; case Ext.form.Action.SERVER_INVALID : Ext.Msg.alert('错误!', action.result.hm.opro_desc); } } });
相关文章推荐
- Column store index 列数据如何匹配成行数据?
- Column store index 列数据如何匹配成行数据?
- [ASP.NET]GridView的Row.Cells[ColumnIndex]如何改用ColumnName來使用
- Column store index 列数据如何匹配成行数据?
- 如何通過編程獲取列表項目的附件以及多行文本中的文件內容
- 如何通過編程獲取列表項目的附件以及多行文本中的文件內容
- android 如何将imageCursor.getColumnIndex(MediaStore.Audio.AlbumColumns.ALBUM_KEY)中的到的专辑封面放入view中显示
- WPF 中如何使得DataGrid的Column有鼠标点击相应
- Android 模糊搜索rawquery bind or column index out of range: handle 0x2fb180 报错
- thinkphp如何隐藏index.php之IIS和nginx
- 如何在深层嵌套ngRepeat中获取不同层级的$index
- 如何加快 index 索引的时间
- PHP5.4+内置webserver,Yii中如何隐藏index.php,让URL rewrite
- 浅述SQL Server的聚焦强制索引查询条件和Columnstore Index
- 如何将 DBCC INDEXDEFRAG 执行的结果插入到表中
- 如何加快建 index 索引 的时间
- [导入]如何在datagrid中控制hyperlinkcolumn的属性
- FAQ(52):java.sql.SQLException: Column Index out of range, 0 > 13. at com.mysql.jdbc.ResultSet.getInt
- Index column size too large. The maximum column size is 767 bytes.
- 如何得到DropDownDW子数据窗口中Display Column的内容