Inserting Data in Extjs Grid using rowediting plugin
I've being having an issue trying tu update some data from Grid using
Rowediting Plugin. I have a table Called Embarque with this structure:
CREATE TABLE [dbo].[Embarque](
[IdFichaTransporte] [int] NOT NULL,
[NumEmbarque] [int] NOT NULL,
[FechaDespacho] [smalldatetime] NOT NULL,
[IdOrigen] [int] NOT NULL,
[Factura] [varchar](15) NOT NULL,
[IdGrower] [int] NOT NULL,
[EdtEq] [varchar](20) NOT NULL,
[IdConsignee] [int] NOT NULL,
[IdBroker] [int] NOT NULL,
[NumAwb] [varchar](15) NOT NULL,
[IdAerolinea] [int] NOT NULL,
[TarifaAwb] [float] NOT NULL,
[TarifaExportador] [float] NULL,
[FechaVuelo] [smalldatetime] NOT NULL,
[EtdEta] [varchar](50) NOT NULL,
[Skids] [int] NOT NULL,
[Cajas] [int] NOT NULL,
[Peso] [float] NOT NULL,
[Dua] [varchar](20) NULL,
[Observaciones] [varchar](100) NULL,
[Estado] [int] NOT NULL,
[FechaCreacion] [smalldatetime] NULL,
[IdDestino] [int] NULL,
[Destino] [varchar](5) NULL,
CONSTRAINT [PK_Embarque] PRIMARY KEY CLUSTERED
(
[IdFichaTransporte] ASC,[NumEmbarque] ASC
)
So i'm having troubles when i try to insert or update a record. Although
i'm getting a success message, in my database are nothing and i'am not
getting any error.
This is my add method:
var fechaact = new Date();
Ext.grid.RowEditor.prototype.cancelBtnText = "Cancelar";
Ext.grid.RowEditor.prototype.saveBtnText = "Guardar";
var gridft = this.getGridTransportes();
var storeft = gridft.getStore();
var count = storeft.getCount() ;
var grid = this.getGridEmbarques();
var plugin = grid.editingPlugin;
var store2 = grid.getStore();
var curnumemb = 0;
var ftstore =       
Ext.data.StoreManager.lookup('ListaFichasTransporte').getAt(0).get('NumEmbarque');
var odstore = 
Ext.data.StoreManager.lookup('ListaOrigenDestino').getAt(0).get('Nombre');
var lexstore = 
Ext.data.StoreManager.lookup('ListaGrowers').getAt(0).get('Nombre');
var lcstore = 
Ext.data.StoreManager.lookup('ListaConsignatarios').getAt(0).get('Nombre');
var lbstore = 
Ext.data.StoreManager.lookup('ListaBrokers').getAt(0).get('Nombre');
var lastore = 
Ext.data.StoreManager.lookup('ListaAerolineas').getAt(0).get('Nombre');
store2.each(function(record,index){
if(record.get("IdFichaTransporte") == count)
{
    if( curnumemb <  record.get("NumEmbarque") )
    curnumemb = record.get("NumEmbarque");
}
});
plugin.cancelEdit();
var r = Ext.create('MyApp.model.Embarque', {
IdFichaTransporte: count,
NumEmbarque: curnumemb+1,
FechaDespacho: fechaact,
Origen: odstore,
Factura: '000',
Exportador: lexstore,
EtaEq: '01/01/2013 AM',
Consignatario: lcstore,
Broker: lbstore,
NumAwb: '000 0000 0000',
Aerolinea: lastore,
TarifAwb: '0.00',
TarifaExportador: '0.00',
FechaVuelo: fechaact,
EtdEta: '00:00hrs/00:00hrs',
Skids: '0',
Cajas: '0',
Peso: '0.00',
Dua: '',
Observaciones: '',
Estado: 'ACTIVO',
IdOrigen: '1',
IdGrower: '3',
IdConsignee: '5',
IdBroker: '6',
IdAerolinea: '7',
IdEstado: '1',
IdDestino: '4',
Destino: 'MIAMI'
});
store2.insert(0, r);
plugin.startEdit(0, 0);
This seems to work ok... Then when i press my button to send the info to
my database... it show me a success message. This is my Save button code:
var grid    = this.getGridEmbarques();
var plugin  = grid.editingPlugin;
var store2  = grid.getStore();
store2.sync({
success: function(batch) {
    console.log(batch);
    Ext.Msg.alert('Success', 'Cambios guardados satisfactoriamente.');
},
failure: function(batch) {
    console.log(batch);
    Ext.Msg.alert('Operación Fallida',  
batch.operations[0].request.scope.reader.jsonData['message']);
  }
});
}
Well i had not defined IDPROPERTY in model because this table has a
combined Id. But i had noticed althoug i put a correct value in the grid
before send to server... after i press the save button Both Id of this
table come to be 1... and there is nothing in the database. Any Ideas what
could i do?
I had noticed my store calls my read method instead of my write or update
method. What could i be doing wrong?
Thank you in advance
 
No comments:
Post a Comment