1. #1
    Sencha Premium Member
    Join Date
    Apr 2011
    Posts
    53
    Vote Rating
    1
    rh_it is on a distinguished road

      0  

    Default Problem with CRUD actions

    Problem with CRUD actions


    Hello I got a little problem, how can I call a CRUD action "update" from my button? Is it possible? I tried many ways but theres nothing to do... here it is the code I wrote...


    the Store
    Code:
    var store = Ext.create('Ext.data.Store', {
    	groupField: 'project',
    	model: 'myItems',
    	autoLoad: false,
    	autoSync: true,
    	proxy: {
    	    type: 'ajax',
    	    api: {
    		create	: '/myPrj/myServlet?cmd=create',
    		read	: '/myPrj/myServlet?cmd=read',
    		update	: '/myPrj/myServlet?cmd=update',
    		destroy	: '/myPrj/myServlet'
    	    },
    	    reader: {
    		type: 'xml',                
    		successProperty: 'success',
    		record: 'row',
    		idProperty: 'id',
    		messageProperty: 'message'
    	    },
    	    writer: {
    		type: 'json',
    		writeAllFields: true,
    		root: 'data'
    	    },
    	    listeners: {
    		exception: function(proxy, response, operation){
    		    Ext.MessageBox.show({
    			title: 'REMOTE EXCEPTION',
    			msg: operation.getError(),
    			icon: Ext.MessageBox.ERROR,
    			buttons: Ext.Msg.OK
    		    });
    		}
    	    }
    	}
    });

    and the Button:
    Code:
    .... },{
    	xtype: 'button',
    	hidden: false,
    	itemId: 'removeItem',
    	text: 'Remove',
    	iconCls: 'icon_removeMyItem',
    	handler: function remove() {
    	    var sm = Ext.getCmp('myGrid').getSelectionModel();
    
    
    
    
    	    rowEditing.cancelEdit();
    	    store.remove(sm.getSelection());
    
    
    
    
    	    if (store.getCount() > 0) {
    		sm.select(0);
    	    }
    	},
    	disabled: true
    }, { ...

    many thanks

  2. #2
    Sencha Premium Member
    Join Date
    Apr 2011
    Posts
    53
    Vote Rating
    1
    rh_it is on a distinguished road

      0  

    Thumbs up


    I solved by myself, it was just a misstype!
    I post here what I did, It may help somebody else...


    Code:
    var store = Ext.create('Ext.data.Store', {
    	groupField: 'project',
    	model: 'myItems',
    	autoLoad: false,
    	autoSync: true,
    	proxy: {
    	    type: 'ajax',
    	    api: {
    		create	: '/myPrj/myServlet?cmd=create',
          read		: '/myPrj/myServlet?cmd=read',
    		update	: '/myPrj/myServlet?cmd=update',
    		destroy	: '/myPrj/myServlet?cmd=destroy'
    	    },
    	    reader: {
    		type: 'xml',                
    		successProperty: 'success',
    		record: 'row',
    		idProperty: 'id',
    		messageProperty: 'message'
    	    },
    	    writer: {
    		type: 'json',
    		writeAllFields: true,
    		root: 'data'
    	    },
    	    listeners: {
    		exception: function(proxy, response, operation){
    		    Ext.MessageBox.show({
    			title: 'REMOTE EXCEPTION',
    			msg: operation.getError(),
    			icon: Ext.MessageBox.ERROR,
    			buttons: Ext.Msg.OK
    		    });
    		}
    	    }
    	}
    });

    then the button:
    Code:
    .... },{	xtype: 'button',
    	hidden: false,
    	itemId: 'removeItem',
    	text: 'Remove',
    	iconCls: 'icon_removeMyItem',
    	scope: this,
    	handler: function() {
    	    var selection =  Ext.getCmp('myGrid').getView().getSelectionModel().getSelection()[0];
    	    if (selection) {
    		store.remove(selection);
    	    }				
    	},
    	disabled: true
    }, { ...

    I just semplified the previous code then I've declared the "destroy" event (missed before) called when the Remove button is pushed! That's all.


    Merry Christmas