Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: why CRUD(Grid row-edit) alwasy send create instead of update ?

  1. #1
    Sencha User masoud_tamizy's Avatar
    Join Date
    Oct 2011
    Posts
    108
    Answers
    1

    Default why CRUD(Grid row-edit) alwasy send create instead of update ?

    i create a row-edit grid (CRUD) . but it sends request as create operation always instead of update (when i press update button) . how can i do it (update) ?

  2. #2
    Touch Premium Member
    Join Date
    Jun 2011
    Posts
    1,102
    Answers
    113

    Default

    this happens mostly when you are not assigning an id to your records. If you are not, you need to add an id field to your store model:

    Code:
    {name: 'id', type: 'int'}
    and assign a unique ID to your records. Newly created records are assigned ID '0' and if you do not have an id field, it might confuse an edited record as a new one. if this doesn't answer your question, then post the code of your store and grid.

  3. #3
    Sencha User
    Join Date
    Jan 2012
    Posts
    1,376
    Answers
    347

    Default

    In case your record id is not 'id', then you can use idProperty to set record id field when defining your model.

  4. #4
    Sencha User masoud_tamizy's Avatar
    Join Date
    Oct 2011
    Posts
    108
    Answers
    1

    Default

    thanks , but now , when i press update button in row-edit , happens nothig !!!

  5. #5
    Touch Premium Member
    Join Date
    Jun 2011
    Posts
    1,102
    Answers
    113

    Default

    without looking at the code, its difficult to say.

  6. #6
    Sencha User masoud_tamizy's Avatar
    Join Date
    Oct 2011
    Posts
    108
    Answers
    1

    Default my code is :

    Code:
    Ext.require([
        'Ext.data.*',
        'Ext.grid.*',
        'Ext.panel.*',
        'Ext.form.*',
        'Ext.util.*',
        'Ext.tip.*',
        'Ext.Action',
        'Ext.ux'
    ]);
    
    Ext.onReady(function() {
    
    Ext.define('User', {
        extend: 'Ext.data.Model',
        fields: [
            { name: 'national_code', type: 'string' },
            { name: 'user_id', type: 'int' },
            { name: 'first_name', type: 'string' },
            { name: 'last_name', type: 'string' },
            { name: 'father_name', type: 'string' },
            { name: 'sh_sh', type: 'string' },
            { name: 'sh_s_sh', type: 'string' },
            { name: 'gender', type: 'string' },
            { name: 'birth_date', type: 'date' },
            { name: 'birth_location', type: 'string' },
            { name: 'email', type: 'email' },
            { name: 'home_address', type: 'string' },
            { name: 'home_phone', type: 'string' },
            { name: 'postal_code', type: 'string' },
            { name: 'job_title', type: 'string' },
            { name: 'job_address', type: 'string' },
            { name: 'job_phone', type: 'string' },
            { name: 'mobile', type: 'string' },
            { name: 'fax', type: 'string' },
            { name: 'comment', type: 'string' }
        ],
        idProperty:"user_id",
        validations: [
            {type: 'presence',  field: 'national_code'},
            {type: 'presence',  field: 'first_name'},
            {type: 'presence',  field: 'last_name'},
            {type: 'presence',  field: 'father_name'},
            {type: 'presence',  field: 'gender'},
            {type: 'presence',  field: 'home_address'},
            {type: 'presence',  field: 'home_phone'},
            {type: 'presence',  field: 'postal_code'},
            {type: 'inclusion', field: 'gender',   list: ['????', '????']}
        ]
    });
    var sex = Ext.create('Ext.data.Store', {
        fields: ['abbr', 'name'],
        data : [
            {"abbr":"M", "name":"????"},
            {"abbr":"F", "name":"????"}
        ]
    });
    var userstore = Ext.create('Ext.data.Store', {
        id:'userstore',
        model: 'User',
        autoLoad: true,
        autoSync: true,    
        proxy: {
            type: 'ajax',
            noCache:true,
            api:{
                read: 'PHP/user_real/read.php',
                create:'PHP/user_real/create.php',
                update: 'PHP/user_real/update.php',
                destroy: 'PHP/user_real/delete.php'
            },
            reader : {type:'json',root:'users',successProperty: 'success',messageProperty: 'message'},
            writer : {type:'json',root:'users',writeAllFields: true/*,successProperty: 'success'*/},
            listeners: {
                    exception: function(proxy, response, operation){
                        Ext.MessageBox.show({
                            title: 'REMOTE EXCEPTION',
                            msg: operation.getError(),
                            icon: Ext.MessageBox.ERROR,
                            buttons: Ext.Msg.OK
                        });
                    }
            }
        },
        listeners: {
                write: function(proxy, operation){
                    if (operation.action == 'destroy') {
                        //main.child('#form').setActiveRecord(null); // insert action to perform fired destroy
                        alert('destroy operation selected');
                    }
                    Ext.example.msg(operation.action, operation.resultSmessageet);
                }
        }
    });
        var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
            clicksToMoveEditor: 1,
            errorSummary:false   
        });
    
        var grid = Ext.create('Ext.grid.Panel', {
            listeners: {
       
            },
            store: userstore,
            selType: 'rowmodel',// 'cellmodel'
            loadMask: true,
            plugins:  [rowEditing],
            columns: [
            {    dataIndex: 'national_code',
                width: 75,
                hideable: false,
                header:'??????',
                sortable:false,
                align:'right',
                editor: {    id:'national',
                            xtype:'numberfield',
                            hideTrigger: true,
                            allowBlank: false,
                            mouseWheelEnabled: false,
                            keyNavEnabled: false,
                            allowDecimals:false,
                            minLengthText:"! ?? ???? 10 ??? ?? ????",
                            maxLength:10,minLength:10,
                            selectOnFocus:true,
                            enforceMaxLength:true,
                            listeners:{
                                blur:function(me){
                                    var code=me.getValue();
                                    Ext.Ajax.request({
                                        url: 'php/user_real/national.php',  
                                        params: 'code='+code,
                                        success: function(response) {
                                            if (response.responseText==1){
                                                me.focus(true);
                                                alert('! ?????? ?????? ??');
                                            }
                                        },
                                        failure: function() {/* do some things on failure*/}
                                    });
                                }
                            }
                } 
            },{    dataIndex:'first_name',
                text:'???',
                width: 75,
                align:'right',
                field: {xtype:'textfield',allowBlank: false} 
            },{    dataIndex:'last_name',
                text:'?????',
                width: 75,
                align:'right',
                field: {xtype:'textfield',allowBlank: false}
            },{    dataIndex:'father_name',
                text:'??? ???',
                width: 75,
                align:'right',
                field: {xtype:'textfield',allowBlank: false}
            },{    dataIndex:'sh_sh',
                text:'????? ????????',
                width: 90,
                align:'right',
                sortable:false,
                field: {xtype:'numberfield',hideTrigger: true,allowBlank: true}
            },{    dataIndex:'sh_s_sh',
                width: 125,
                text:'????? ????? ????????',
                sortable:false,
                align:'right',
                field: {xtype:'textfield',allowBlank: true,selectOnFocus:true}
            },{    dataIndex:'gender',
                text:'?????',
                width: 50,
                align:'right',
                editor: {xtype:'combo',store: sex,editable:false,allowBlank: false}
            },{    dataIndex:'birth_date',
                text:'?????  ????',
                width: 75,
                align:'right',
                hidden:true,
                renderer : Ext.util.Format.dateRenderer('d/m/Y'),
                editor: {xtype:'datefield',allowBlank: true,selectOnFocus:true}
            },{    dataIndex:'birth_location',
                text:'??? ????',
                width: 100,
                hidden:true,
                align:'right',
                field: {type:'textfield',allowBlank: true,selectOnFocus:true}
            },{    dataIndex:'email',
                text:'??? ?????????',
                width: 150,
                hidden:true,
                align:'left',
                field: {type:'textfield',vtype:'email',allowBlank:true,selectOnFocus:true}
            },{    dataIndex:'home_address',
                text:'???? ????',
                width: 175,
                align:'right',
                field: {type:'textfield',allowBlank: false,selectOnFocus:true}
            },{    dataIndex:'home_phone',
                text:'???? ????',
                width: 80,
                align:'right',
                field: {xtype:'numberfield',hideTrigger: true,allowBlank: false}
            },{    dataIndex:'postal_code',
                text:'?? ????',
                width: 75,
                align:'right',
                field: {xtype:'numberfield',hideTrigger: true}
            },{    dataIndex:'job_title',
                text:'???',
                align:'right',
                hidden:true,
                field: {xtype:'textfield',allowBlank: true,selectOnFocus:true}
            },{    dataIndex:'job_address',
                text:'???? ??? ???',
                align:'right',
                hidden:true,
                field: {type:'textfield',allowBlank: true,selectOnFocus:true}
            },{    dataIndex:'job_phone',
                text:'???? ??? ???',
                align:'right',
                width: 80,
                hidden:true,
                field: {xtype:'numberfield',hideTrigger: true,allowBlank: true}
            },{    dataIndex:'mobile',
                text:'???? ?????',
                width: 80,
                align:'right',
                field: {xtype:'numberfield',hideTrigger: true,allowBlank: true},
                hidden:true
            },{    dataIndex:'fax',
                text:'????',
                width: 80,
                align:'right',
                hidden:true,
                field: {xtype:'numberfield',hideTrigger: true,allowBlank: true}
            },{    dataIndex:'comment',
                text:'???????',
                align:'right',
                hidden:true
            }],
            title: '???? ???????',
            tbar : [{
                itemId : 'remove',
                text : '????? ???',
                iconCls: 'employee-remove',
                handler : function() {
                    var select = grid.getSelectionModel();
                    rowEditing.cancelEdit();
                    userstore.remove(select.getSelection());
                },
                disabled : true
            }, {
                text : '????? ????',
                iconCls: 'employee-add',
                handler : function() {
                    var record = Ext.create('User',{
                        national_code: '1234567890',
                        first_name: '???',
                        last_name: '?????',
                        father_name: '??? ???',
                        gender: '????',
                        home_address:'???? ????',
                        home_phone:'1234567890',
                        postal_code:'1234567890'
                    });
                    rowEditing.cancelEdit();
                    //userstore.save();
                    //insert at top
                    userstore.insert(0, record);
                    //edit at row 0
                    rowEditing.startEdit(0, 0);
                    //Ext.example.msg('Done','in the name of god');
                }
            } ],
            height:575,
            width:1366,//viewConfig: {forceFit: true},
            listeners: {
                    select: function(rowModel, record) {
                        var code = record.get('national_code');
                        var id = record.get('user_id');
                        console.log('????? ????? ?????? ?? :',code);
                        console.log('????? ?????? :',id);
                    },
                    selectionchange: function(selModel, selected) {
                         var rec = grid.getSelectionModel().getSelection()[0];
                        if (rec) {
                            console.log("Sell " + rec.get('last_name'));
                        } else {
                            console.log('Please select a company from the grid');
                        }
                    }
            },
            renderTo: Ext.getBody(),
             tools: [{ type: 'refresh' }]
        });
        grid.getSelectionModel().on('selectionchange', function(selModel, selections){
            grid.down('#remove').setDisabled(selections.length === 0);
        });
       
        persian = (function() {
            return {
                init: function() {
                    Ext.tip.QuickTipManager.init();
                        Ext.Ajax.request({
                            url: "JS/fa.js",
                            success: this.onSuccess,
                            failure: this.onFailure,
                            scope: this 
                        });
                },
                onSuccess: function(response, opts) {
                    eval(response.responseText);
                    //Ext.Msg.alert('Status', 'Changes saved successfully.');
                    //this.setupDemo();
                },
                onFailure: function() {
                    Ext.Msg.alert('???? ???????', '! ???????? ???? ????? ?? ??? ????? ??? ???');
                    //this.setupDemo();
                }
            };
        })();
        persian.init();
    });

  7. #7
    Sencha User masoud_tamizy's Avatar
    Join Date
    Oct 2011
    Posts
    108
    Answers
    1

    Default PLEASE HELP !!!


  8. #8
    Touch Premium Member
    Join Date
    Jun 2011
    Posts
    1,102
    Answers
    113

    Default

    I am sorry i couldnt find anything wrong in your code. Try without using idProperty and changing ur user_id field to 'id'. Although it should work with idProperty but just give it a try.

  9. #9
    Sencha User masoud_tamizy's Avatar
    Join Date
    Oct 2011
    Posts
    108
    Answers
    1

    Default hi Farish

    i did it , but didn't work again !
    i saw this example :
    http://docs.sencha.com/ext-js/4-0/#!...er/writer.html
    but i don't have anything more ... for update !!!

    can anyone help me ???

  10. #10
    Sencha User masoud_tamizy's Avatar
    Join Date
    Oct 2011
    Posts
    108
    Answers
    1

    Default

    Please Helppppppppppp !!!

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •