PDA

View Full Version : Problem with rowEditing Plugin.



OtavioF
19 Oct 2012, 6:17 AM
I'm having a problem to get the values typed in the rowEditing plugin. When I type the values, I can't get it back with function.

error message: Uncaught TypeError: Cannot call method 'get' of undefined.

I hope you can help me, here's the script code:


Ext.define('Person', { extend: 'Ext.data.Model',
idProperty: 'dadosdobanco',
fields: [
{name: 'idproduto_pontuacao'},
{name: 'ano'},
{name: 'valor'},
{name: 'menor'},
{name: 'maior'}
]
});


var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
listeners: {
clicksToEdit: 2,
edit: function(e){

Ext.Ajax.request({
url: "../comercial/produtos",
method:'POST',
params: {
acao: 'salvapontuacao',
ano: e.record.get('ano'),
valor: e.record.get('valor'),
menor: e.record.get('menor'),
maior: e.record.get('maior')

},
beforeSend: function(){
},
success: function(e){
if(acao == 'inserir'){
store_pontuacao.load();
}


}
})
}
}

});


var store_pontuacao = Ext.create('Ext.data.Store', {
autoLoad: true,
//autoSync: true,
model: 'Person',
proxy: {
type: 'rest',
url: '../comercial/produtos',
reader: {
type: 'json',
root: 'data'
},
writer: {
type: 'json'
},
actionMethods: {
create : 'POST',
read : 'POST',
update : 'POST',
destroy: 'POST'
},
extraParams:{
acao: 'pontuacao'
}
}
});

//Cria a grid da aba de pontuação

var grid2 = Ext.create('Ext.grid.Panel', {
width: 740,
height: 275,
plugins: [rowEditing],
store: store_pontuacao,
columns: [{
text: 'Ano',
sortable: true,
dataIndex: 'ano',
width: 179,
field: {
xtype: 'textfield'
}
}, {
text: 'Valor',
sortable: true,
dataIndex: 'valor',
width: 180,
field: {
xtype: 'textfield'
}
}, {
text: 'Menor',
sortable: true,
dataIndex: 'menor',
width: 188,
field: {
xtype: 'textfield'
}
}, {
text: 'Igual ou Maior Pt.',
sortable: true,
dataIndex: 'maior',
width: 174,
field: {
xtype: 'textfield'
}
}],
dockedItems: [{
xtype: 'toolbar',
items: [{
text: 'Novo',
icon: '../source/images/add.png',
handler: function(){
// empty record
store_pontuacao.insert(0, new Person());
rowEditing.startEdit(0, 0);
}
}, '-', {
itemId: 'delete',
text: 'Excluir',
icon: '../source/images/delete.png',
disabled: true,
handler: function(){
if (selection) {
store_pontuacao.remove(selection);
}
}
}]
}]
});
grid2.getSelectionModel().on('selectionchange', function(selModel, selections){
grid2.down('#delete').setDisabled(selections.length === 0);
});

scottmartin
19 Oct 2012, 8:32 AM
Please review the API for the edit event:
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.grid.plugin.RowEditing-event-edit


edit: function(ed, e) {

Also .. what is the purpose for make an ajax call and loading the store on each edit?

Scott.

OtavioF
19 Oct 2012, 9:52 AM
I did it to update the store at each edit that i do. The problem is that i want to save all the data in one session, then save it at the Database.

Now i have a problem when i insert the data, the grid updates but the values vanish, though it is saved in the session.
How can i update the grid with the session's data without them disappear?

OtavioF
19 Oct 2012, 11:28 AM
I've already solved my problem.

Thanks Scott.