0

I am new to Ext js, using Extjs 4.1.1. I am trying to update a record(User - model) by editing(View- Edit.js) it. But when the request is sent, operation is being aborted in the mid and not getting completed.
Is extra code to be written to save or there is some flaw in my code?

Please find my code below.

app.js

    Ext.application({

name: 'AM',

appFolder:'app',

controllers:['Users'],

requires:['AM.view.user.List','AM.Configuration'],

launch:function(){

    Ext.create('Ext.container.Viewport',{
        layout:'fit',
        items:[{
                xtype:'userlist',
                title:'Users',
                html:'List of users will go here'
            }   
        ]
    });
}});

Model

Ext.define('AM.model.User',{
extend:'Ext.data.Model',
fields: ['id','name','email']});

Store

Ext.define('AM.store.Users',{
extend: 'Ext.data.Store',
model: 'AM.model.User',
autoLoad: true,
idProperty:'id',

proxy:{
    type:'ajax',
    url: 'data/users.json',
    api:{
        read: 'data/users.json',
        update: 'data/updateUsers.json'
    },
    reader:{
        type: 'json',
        root: 'users',
        successProperty:'success',
    }   
}});

View

    Ext.define('AM.view.user.Edit',{

extend: 'Ext.window.Window',

alias: 'widget.useredit',

title: 'Edit User',

layout:'fit',

autoShow:'true',

initComponent: function(){

        this.items = [{

                    xtype:'form',
                    items:[{
                        xtype:'textfield',
                        name: 'name',
                        fieldLabel: 'Name'
                    },{
                        xtype:'textfield',
                        name: 'email',
                        fieldLabel: 'Email'
                    }]
            }];

        this.buttons = [{
                text:'Save',
                action:'save'
            },{
                text:'Cancel',
                scope:this,
                handler: this.close
        }]

    this.callParent(arguments);
}});  

Controller

    Ext.define('AM.controller.Users',{
extend: 'Ext.app.Controller',

views:['AM.view.user.List','AM.view.user.Edit'],

requires:['AM.view.user.List'],

stores:['Users'],

models:['User'],

init: function(){
    console.log('Initialized Users!! This happens before the application launch function is called');   
    this.control({

        'userlist':{
             itemdblclick: this.onEditUser
        },
        'useredit button[action=save]':{
            click: this.updateUser
        }

    });
},

onEditUser: function(grid,record){
    console.log('called on Edit User.. for user '+record.get('name'));
    var view = Ext.widget('useredit');
    view.down('form').loadRecord(record);
},

updateUser: function(button){
    console.log('Clcked save button');
    var win = button.up('window'),
    form = win.down('form'),
    record = form.getRecord(),
    values = form.getValues();

    record.set(values);
    win.close();
    this.getUsersStore().sync();
}});
Supereme
  • 2,379
  • 12
  • 46
  • 67

2 Answers2

0

Try add to store proxy: writer:new Ext.data.JsonWriter()

Boris Gappov
  • 2,483
  • 18
  • 23
0

try this method

grid.insert(rowIndex,[values])
Alexis Pigeon
  • 7,423
  • 11
  • 39
  • 44
Surya Prakash Tumma
  • 2,153
  • 4
  • 27
  • 47