当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - ExtJs 4.2 editable grid handling response

问题描述:

I have a model,a store and a grid:

MODEL

Ext.define('demo.mdlTemaco', {

extend: 'Ext.data.Model',

fields: [

{name: 'id', type: 'string' , mapping: ''},

{name: 'id_empresa', type: 'string' , mapping: ''},

{name: 'cif', type: 'string' , mapping: ''},

{name: 'acronimo', type: 'string' , mapping: ''},

{name: 'competidor', type: 'string' , mapping: ''},

{name: 'descripcion', type: 'text' , mapping: ''}

]

});

STORE

Ext.define('demo.strTemaco', {

extend: 'Ext.data.Store',

model: 'demo.mdlTemaco',

autoLoad: false,

autoSync: true,

proxy: {

type: 'ajax',

pageParam: undefined,

startParam: undefined,

limitParam: undefined,

api: {

read: 'read.php',

update: 'update.php',

create: ''

},

reader: {

type: 'json',

root: 'data',

idProperty: 'id',

totalProperty: 'total',

successProperty: 'success',

messageProperty : 'message',

},

writer: {

root: 'records',

encode: true,

writeAllFields: true

}

}

});

GRID

var cellEditing = Ext.create('Ext.grid.plugin.CellEditing',{

clicksToEdit: 2

});

Ext.create('Ext.grid.Panel', {

itemId:'viewGridTemaco',

title:'<span style="color:#C85E00;">Title</span>',

store: Ext.create('demo.strTemaco'),

stripeRows: true,

loadMask: true,

selType: 'checkboxmodel',

plugins: [cellEditing],

columns:{

defaults:{

hideable:false,

draggable:false

},

items:[

{header:'<span style="color:#C85E00;">Id</span>' ,dataIndex:'id' ,itemId:'IdConcurso' ,flex:1 },

{header:'<span style="color:#C85E00;">Empresa</span>' ,dataIndex:'id_empresa' ,itemId:'Empresa' ,flex:1 },

{header:'<span style="color:#C85E00;">CIF</span>' ,dataIndex:'cif' ,itemId:'CIF' ,flex:2 ,editor:{allorBlanck:false}},

{header:'<span style="color:#C85E00;">Acronimo</span>' ,dataIndex:'acronimo' ,itemId:'Acronimo' ,flex:2 ,editor:{allorBlanck:false}},

{header:'<span style="color:#C85E00;">Competidor</span>' ,dataIndex:'competidor' ,itemId:'Competidor' ,flex:3 ,editor:{allorBlanck:false}},

{header:'<span style="color:#C85E00;">Descripcion</span>',dataIndex:'descripcion' ,itemId:'Descripcion' ,flex:3 ,editor:{allorBlanck:false}}

]

}

renderTo: Ext.getBody()

});

In my controller I have a listener to handle the editing of the cell:

Ext.ComponentQuery.query('viewGridTemaco')[0].getStore().addListener('update',function(store, record, operation, modifiedFieldNames, eOpts){

store.commitChanges();

},this);

And in the update php if there is an error for some reasons I send:

echo json_encode(array(

"success" => //A number between 1-5 depending on the error

));

And I want to handle this response in the controller to show a message box.Any idea on how to do this?

网友答案:

Finally I solved the probled disabling autoSync in store and in the contoller,in update listener I use:

store.sync({
                scope:this,
                success : function(response){

                },
                failure:function(response){
                    var mensaje;
                    switch(Ext.JSON.decode(response.operations[0].error)) 
                    {
                        case 1:
                            mensaje="Messagge 1";
                            break;
                        case 2:
                            mensaje="Messagge 2";
                            break;
                        case 3:
                            mensaje="Messagge 3";
                            break;
                        case 4:
                            mensaje="Messagge 4";
                            break;
                    }
                    Ext.Msg.show({ 
                        title: 'ADVERTENCIA', 
                        msg:mensaje,
                        icon: Ext.MessageBox.WARNING, 
                        buttons: Ext.Msg.OK,
                        closable:false
                    });
                    store.rejectChanges();
                }
            });

And my update.php response is:

echo json_encode(array(
"success"   => false,
"message"   => //number between 1-5
));
分享给朋友:
您可能感兴趣的文章:
随机阅读: