PDA

View Full Version : 'return o.id' working with Record



ehuertasf
30 Jan 2010, 4:28 AM
Hello,
This is day 2 without sleeping and maybe the solution to my problem is simple but I can hardly see the screen by now.

I've an EditorGridPanel where I want to add record by record and then save it to a DB but my problem is that when I try to add a new record to that grid FireBug shows an error:


Ext.data.Store = function(config){
this.data = new Ext.util.MixedCollection(false);
this.data.getKey = function(o){
return o.id; <- This line
}; Here is my code and I hope you can help me to find out what is wrong :-/. Thanx

My record:


var newPersona = Ext.data.Record.create([
{name: 'item', type: 'int'},
{name: 'codper', type: 'int'},
{name: 'apepatper', type: 'string'},
{name: 'apematper', type: 'string'},
{name: 'nomper', type: 'string'},
{name: 'destipdoc', type: 'string'},
{name: 'numdocper', type: 'string'},
{name: 'codpue', type: 'int'},
{name: 'despue', type: 'string'},
{name: 'codpacchk', type: 'int' },
{name: 'despacchk', type: 'string' }
]);My ColumnModel:


var cm_solpersonas = new Ext.grid.ColumnModel(
[{header: 'item', readonly: true, dataIndex: 'item', hidden: true},
{id : 'codper', header: 'codper', readonly: true, dataIndex: 'codper', hidden: true},
{header: 'Apellido Paterno', readonly: true, dataIndex: 'apepatper', hidden: false},
{header: 'Apellido Materno', readonly: true, dataIndex: 'apematper', hidden: false},
{header: 'Nombres', readonly: true, dataIndex: 'nomper', hidden: false},
{header: 'Documento', readonly: true, dataIndex: 'destipdoc', hidden: false},
{header: 'Número', readonly: true, dataIndex: 'numdocper', hidden: false},
{header: 'codpue', readonly: true, dataIndex: 'codpue', hidden: true},
{header: 'Puesto', readonly: true, dataIndex: 'despue', hidden: false},
{header: 'codpacchk', readonly: true, dataIndex: 'codpacchk', hidden: true},
{header: 'Check Pack', readonly: true, dataIndex: 'despacchk', hidden: false}
]
);My Store:


var store = new Ext.data.GroupingStore({
proxy :new Ext.data.HttpProxy({url: "query.php?n=0"}),
reader :new Ext.data.JsonReader(newItem),
sortInfo :{field:'codper', direction:'ASC'},
groupField:'destipdoc'});An finally... my Grid:


var grd_personas = new Ext.grid.EditorGridPanel({
id : 'grd_personas',
store : stdetsolper,
title : 'Personas',
cm : cm_solpersonas,
width : 350,
anchor : '100%',
height : 200,
frame : true,
clicksToEdit:1,
layout : 'fit',
autoScroll: true,
selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
tbar :['Persona : ',cboSolBuscaPersona,' Puesto : ',cboPuestos,' Check Pack : ',cbopackcheck,'-',
{
xtype : 'tbbutton',
cls : 'x-btn-icon',
icon : 'files/images_app/plus.png',
handler : function(){
if(selPersona==true && selPuesto==true && selPack==true){
var p = newPersona({
item : stdetsolper.getCount() + 1,
codper : vcodper,
apepatper : vapepatper,
apematper : vapematper,
nomper : vnomper,
destipdoc : vdestipdoc,
numdocper : vnumdocper,
codpue : vcodpue,
despue : vdespue,
codpacchk : vcodpacchk,
despacchk : vdespacchk
});
grd_personas.stopEditing();
stdetsolper.insert(stdetsolper.getCount(), p); <- without this line, no error
grd_personas.getView().refresh();
grd_personas.startEditing(0);
stdetsolper.reload();
}else{
Ext.Msg.show({ title: 'Error de Ingreso',
msg: 'Debe seleccionar los datos necesarios antes de agregar una persona a la solicitud',
buttons: Ext.MessageBox.OK,
icon: Ext.MessageBox.ERROR});
}
}
},
{
xtype : 'tbbutton',
cls : 'x-btn-icon',
icon : 'files/images_app/minus.png'
}
]

});

Animal
30 Jan 2010, 5:40 AM
http://www.extjs.com/deploy/dev/docs/?class=Ext.data.Record&member=create

What does it return?

ehuertasf
30 Jan 2010, 5:47 AM
http://www.extjs.com/deploy/dev/docs/?class=Ext.data.Record&member=create

What does it return?

It says 'id is null or not an object', what id? :-/

Thanx

ehuertasf
30 Jan 2010, 6:10 AM
http://www.extjs.com/deploy/dev/docs/?class=Ext.data.Record&member=create

What does it return?

I forgot to put new before the record... I need to sleep (:|. Thanx for your help, it made me investigate more =D>.

if(selPersona==true && selPuesto==true && selPack==true){
var p = new newPersona({
item : stdetsolper.getCount() + 1,PS: Don´t use Ext or Drive when you haven´t sleep :))

Animal
30 Jan 2010, 6:43 AM
Well done ehuertasf!