Trouble adding rows to grid manually. - Ext JS

作者在使用ExtJS创建网格并尝试添加数据时遇到问题。主要问题是:只有第一列被正确填充,其余列为空;组合框无法正常显示;添加第二行数据时报错。经过排查,发现未正确设置记录ID及未将组合框包装为GridEditor。

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

I'm trying to populate a grid based off rows checked in another grid, but adding rows is proving somewhat tricky.

Grid code:
		this.myData = [['-','-','-','-','-','-','-','-','-']];
		this.ds = new Ext.data.Store({
			proxy:new Ext.data.MemoryProxy(this.myData),
			reader:new Ext.data.ArrayReader({id:0}, [
				{name:"part"},
				{name:"desc"},
				{name:"weight"},
				{name:"failureMode"},
				{name:"timeToFailure"},
				{name:"carton"},
				{name:"transnum"},
				{name:"returnReason"},
				{name:"note"}
			])
		});
		this.ds.load();
		var myColumns = [
		{header: "Part #",width:50,sortable:true},
		{header: "Description",width: 150,sortable: true},
		{header: "Weight",width: 70, sortable: true},
		{header: "Failure Mode",width: hideMode ? 0 : 60, editor: new Ext.form.ComboBox({transform:'failuremode',lazyRender:true,triggerAction:'all'}), sortable: true},
		{header: "Time to Failure", width: hideTime ? 0 : 90, editor: new Ext.form.ComboBox({transform:'timetofailure',lazyRender:true,triggerAction:'all'}), sortable: true},
		{header: "In Carton #", width: 230, editor: new Ext.form.ComboBox({transform:'cartonnum',lazyRender:true,triggerAction:'all'}), sortable: true},
		{header: "RMA #", width: 230, sortable: true},
		{header: "Return Reason", width: hideReason ? 0 : 90, editor: new Ext.form.ComboBox({transform:'returnreason',lazyRender:true,triggerAction:'all'}), sortable: true},
		{header: "Note",width:60,sortable:false,editor: new Ext.form.TextField()}
		];
		this.cm = new Ext.grid.DefaultColumnModel(myColumns);
		this.grid = new Ext.grid.EditorGrid('partcartongrid',{selModel: new Ext.grid.RowSelectionModel({singleSelect:true}),ds: this.ds, cm: this.cm});
		this.grid.render();
Adding to said grid:
		var record = null;
		var values = {};
		for (i = 0; i < quantity; i++) {
			values = {};
			values['part'] = partnum;
			values['desc'] = name;
			values['weight'] = weight;
			values['failureMode'] = 'Constant';
			values['timeToFailure'] = 'Expected Life';
			values['carton'] = insertCarton;
			values['transnum'] = rmanum;
			values['returnReason'] = 'Excess Inventory';
			values['note'] = '';
			record = new Ext.data.Record(values,0);
			this.ds.add(record);
		}
I've also tried putting the records in an array first and then using add.

The first problem is that only the first cell gets a value, the rest are empty. The second problem is that the combobox doesn't show up. When I click on a combobox cell, it gives the error:
Quote:
uncaught exception: Event does not exist: "complete".

Line 0
The third problem is while the first row will get added, any additional ones give the error:
Quote:
r has no properties
https://demo.xteconline.com/system/j...id/GridView.js
Line 746
Looking again, I also see that the initial row filled with -'s has only the first cell filled in as well.
Reply With Quote
  #2  
Old 03-09-2007, 04:59 PM
Default

Damn, figured out why only my first cell was populated. I needed to add the dataIndex param to my columnmodel (which didn't change much so I overlooked that part). Still getting the same error trying to add another row after the first one (r has no properties).

Edit: Also still having trouble with the comboboxes.

HTML for the ones being transformed:
<select id="failuremode" style="display:none">
	<option value="Constant">Constant</option>
	<option value="Intermittent">Intermittent</option>
</select>
<select id="timetofailure" style="display:none">
	<option value="Expected Life">Expected Life</option>
	<option value="Early Failure">Early Failure</option>
	<option value="Failed On Install">Failed on Install</option>
</select>
<select id="cartonnum" style="display:none">
	<option value="Not Shipping">Not shipping</option>
</select>
<select id="returnreason" style="display:none">
<option value="Excess Inventory">Excess Inventory</option>
<option value="Rec'd Incorrect Part">Rec'd Incorrect Part</option>
<option value="Ordered Incorrect Part">Ordered Incorrect Part</option>
</select>
Reply With Quote
  #3  
Old 03-09-2007, 05:17 PM
Default

Edit: For some reason I read it wrong in the constructor that if you pass 0 in, it will generate an ID. But it doesn't, so it was halting due to the fact that two records had the same ID (although I thought I had tried it before without a second parameter and it didn't work). That fixes my problem with adding additional rows.

Still the same problem with my comboboxes. I don't know where that error is coming from. It's basically a copy of the editor grid example with nearly the same parameters to the comboboxes (except for typeAhead).
Reply With Quote
  #4  
Old 03-09-2007, 05:19 PM
Default

You forgot to wrap the field (the combo) in a GridEditor. Take a look at the editor grid example to see what I mean.
Reply With Quote
  #5  
Old 03-09-2007, 05:22 PM
Default

Quote:
Originally Posted by jacksloc
You forgot to wrap the field (the combo) in a GridEditor. Take a look at the editor grid example to see what I mean.
Yeah, I figured that out right as you posted. That's why sometimes shorthand sucks, I looked right over that :?

Seems typing out my thoughts really help though, I seem to find my mistakes faster when I do that....too bad I did them on here though where I look foolish :lol:
Reply With Quote
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值