Results 1 to 2 of 2

Thread: updating database using grid ...

  1. #1
    Sencha User
    Join Date
    Aug 2015
    Location
    Philippines
    Posts
    10

    Default updating database using grid ...

    hi, i try to create a editable grid in sencha architect and the data is comes from my database .. but i got a problem in my updating database .. they nothing changes in my database while i edit it in my grid . i sure the code that i input their is running properly because before i used it .. i tried the code that im going to use .. now i don't know what is the problem in my grid so why didn't update in database. anyone can tell me what is my problem in my coding ? here my codes ..


    View:
    Code:
    Ext.define('MyApp.view.MyForm', {
        extend: 'Ext.form.Panel',
        alias: 'widget.myform',
    
    
        requires: [
            'MyApp.view.MyFormViewModel',
            'Ext.form.Panel',
            'Ext.grid.Panel',
            'Ext.grid.column.Number',
            'Ext.form.field.Display',
            'Ext.form.field.Text',
            'Ext.view.Table',
            'Ext.grid.plugin.RowEditing',
            'Ext.selection.RowModel'
        ],
    
    
        viewModel: {
            type: 'myform'
        },
        height: 250,
        width: 400,
        bodyPadding: 10,
        title: 'My Form',
        defaultListenerScope: true,
    
    
        items: [
            {
                xtype: 'form',
                id: 'mygridData',
                bodyPadding: 10,
                title: 'My Form',
                items: [
                    {
                        xtype: 'gridpanel',
                        title: 'My Grid Panel',
                        store: 'MyJsonStore',
                        columns: [
                            {
                                xtype: 'numbercolumn',
                                dataIndex: 'id',
                                text: 'id',
                                format: '0',
                                editor: {
                                    xtype: 'displayfield',
                                    id: 'colorId',
                                    name: 'colorId'
                                }
                            },
                            {
                                xtype: 'gridcolumn',
                                dataIndex: 'colorcode',
                                text: 'colorcode',
                                editor: {
                                    xtype: 'textfield',
                                    name: 'colorCode'
                                }
                            },
                            {
                                xtype: 'gridcolumn',
                                dataIndex: 'color',
                                text: 'color',
                                editor: {
                                    xtype: 'textfield',
                                    name: 'colorName'
                                }
                            }
                        ],
                        plugins: [
                            {
                                ptype: 'rowediting',
                                listeners: {
                                    edit: 'onRowEditingEdit'
                                }
                            }
                        ],
                        selModel: {
                            selType: 'rowmodel'
                        }
                    }
                ]
            }
        ],
    
    
        onRowEditingEdit: function(editor, context, eOpts) {
            Ext.Ajax.request({
                url: 'data/update/colorUpdate.php',
                method: 'POST',
                params : Ext.getCmp('mygridData').getForm().getFieldValues() ,
                success: function(response){
                    Ext.Msg.alert('success ' + response.status);
                },
                failure: function(response){
                    Ext.Msg.alert('Server Side Failure with Status Code ' + response.status);
                }
    
    
            });
        }
    
    
    });
    json:
    Code:
    Ext.define('MyApp.store.MyJsonStore', {
        extend: 'Ext.data.Store',
    
    
        requires: [
            'MyApp.model.MyModel',
            'Ext.data.proxy.Ajax',
            'Ext.data.reader.Json'
        ],
    
    
        constructor: function(cfg) {
            var me = this;
            cfg = cfg || {};
            me.callParent([Ext.apply({
                storeId: 'MyJsonStore',
                autoLoad: true,
                model: 'MyApp.model.MyModel',
                proxy: {
                    type: 'ajax',
                    url: 'data/itemcolor.php',
                    reader: {
                        type: 'json',
                        rootProperty: 'rows_color'
                    }
                }
            }, cfg)]);
        }
    });
    Model:
    Code:
    Ext.define('MyApp.model.MyModel', {
        extend: 'Ext.data.Model',
    
    
        requires: [
            'Ext.data.field.Field'
        ],
    
    
        fields: [
            {
                name: 'id'
            },
            {
                name: 'color'
            },
            {
                name: 'colorcode'
            }
        ]
    });

  2. #2
    Sencha Premium Member
    Join Date
    May 2010
    Location
    Guatemala, Central America
    Posts
    1,501
    Answers
    13

    Default

    Hi.

    First of all the use of global ID is not a good practice, use itemId instead and locate components via up() & down().

    Now with the update:
    Grid changes data in the store so to persist the data you should use store.sync(). You nee to tell to the ajax proxy what URLs must be called for CRUD or you can use rest proxy and code for GET. POST, PUT & DELETE verbs.

    Regards.

Similar Threads

  1. Replies: 1
    Last Post: 15 Oct 2012, 8:41 AM
  2. Updating record IDs from database
    By amitayh in forum Ext: Discussion
    Replies: 6
    Last Post: 18 Jun 2012, 9:04 AM
  3. Updating grid row after updating store from using form
    By scottmartin in forum Ext 3.x: Help & Discussion
    Replies: 2
    Last Post: 27 Sep 2010, 4:38 AM
  4. EditorGridPanel with Combobox - updating database
    By kpiechowicz in forum Ext 2.x: Help & Discussion
    Replies: 0
    Last Post: 24 Sep 2009, 6:03 AM

Posting Permissions

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