problems with RowSelectionModel - Ext JS

本文探讨了ExtJS中网格组件的选择操作引发的问题,包括单选或多选时出现的错误及解决方案。文中详细分析了使用getSelected和getSelections方法时遇到的具体问题,并提供了调试建议。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

SINGLE ROW
var tcs = grid.getSelectionModel().getSelected();
I get this error
this.selections.getAt is not a function

MULTI-ROW
var tcs = grid.getSelectionModel().getSelections();
doesn't produce any javascript errors, but the array it returns isn't an array of row id's.

Here is my grid setup code:
     // preheats grid
      var cm = new Ext.grid.ColumnModel([
         {header: "ThermoCouple", dataIndex: 'tc', width: 89, sortable: true}, 
         {header: "Target Time", dataIndex: 'time', width: 75, sortable: true} 
      ]);
      var record = Ext.data.Record.create([
        {name: 'tc', mapping: 'tc'},
        {name: 'time', mapping: 'time'},
      ]); 
      var reader = new Ext.data.JsonReader({
        root: 'result',
        id: 'tc',
      }, record);        
      ds = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({url: 'preheat/tc'}),
        reader: reader
      });
      ds.setDefaultSort('tc');
      grid = new Ext.grid.Grid('preheats-grid', {
        ds: ds,
        cm: cm
      });
      grid.addListener('rowdblclick', viewGraph);
      grid.render();
Reply With Quote
  #2  
Old 02-20-2007, 09:01 AM
Default

The 2nd is a "documentation hasn't been updated error". It actually returns an array of the full record objects.

getSelected should return 1 record object, but getAt should be itemAt.

I have fixed both these issues and will be deploying a new zip shortly.
Reply With Quote
  #3  
Old 02-20-2007, 03:14 PM
Default

getSelected() returns a MixedCollection.

What is the index property in the MixedCollection?
Reply With Quote
  #4  
Old 02-20-2007, 03:25 PM
Default

Look at the source for MixedCollection - it's pretty completely documented. You can call item(key), itemAt(index), etc. There's quite a few ways of getting at the data.
__________________
Tim Ryan - Ext JS Support Team
Read BEFORE posting a question / posting a Bug
Use Google to Search - API / Forum
API Doc (3.x | 2.x | 1.x) / FAQ / Wiki / Tutorials / 1.x->2.0 Migration Guide
Reply With Quote
  #5  
Old 02-20-2007, 03:34 PM
Default

Tim -

here is my code:
var deleteRow = sm.getSelected();		
deleteRow.each(function(key) {alert(key + ' : ' + deleteRow.get(key));});
I receive the error deleteRow.each is not a function. However if I use the line
deleteRow.get('title')
it pulls my data out fine...

Any help is appreciated

Aaron
Reply With Quote
  #6  
Old 02-20-2007, 03:53 PM
Default

I haven't done much with this yet, but looking at the code, getSelected returns a Record, not a MixedCollection. Get works b/c Record also has a get method. I would suggest stopping in debug after getSelected and looking at what that object actually is. Maybe it contains the data in a MixeCollection?? - try looking at the internal 'data' property.
__________________
Tim Ryan - Ext JS Support Team
Read BEFORE posting a question / posting a Bug
Use Google to Search - API / Forum
API Doc (3.x | 2.x | 1.x) / FAQ / Wiki / Tutorials / 1.x->2.0 Migration Guide
Reply With Quote
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值