Results 1 to 3 of 3

Thread: Store using POST to update data

  1. #1
    Sencha User
    Join Date
    Jan 2012
    Posts
    2
    Answers
    1
    Vote Rating
    0
      0  

    Default Answered: Store using POST to update data

    I've googled a lot and I can't figure out why my form always use POST to update records. This leads to 409 error from my django server. There's a "id" fields, so what's wrong?

    Code:
        Ext.define('Material', {
            extend: 'Ext.data.Model',
            fields: [
                {name: 'id', type: 'int'},
                {name: 'nome', type: 'string'},
                {name: 'descricao', type: 'string'},
                {name: 'preco_kg', type: 'number'}
            ]
        });
    
    
        var proxy = Ext.create("Ext.data.HttpProxy", {
            type: 'rest',
            url: '/api/material',
            reader: {
                type: 'json',
                root: 'data'
            }
        });
    
    
        var materialStore = Ext.create('Ext.data.Store', {
            storeId:'materialStore',
            model: "Material",
            proxy: proxy,
            autoLoad: true,
            autoSync: true,
            idProperty: 'id',
            api: {
                create: '/api/material',
                read: '/api/material',
                update: '/api/material',
                destroy: '/api/material'
            }
    
    
        });
    
    
    
    
        var toolbar = Ext.create('Ext.toolbar.Toolbar', {
            region: 'north',
            items: [
                {
                    // xtype: 'button', // default for Toolbars
                    text: 'Novo'
                },
                {
                    text : 'Editar'
                },
                {
                    text: 'Excluir'
                },
                // begin using the right-justified button container
                '->', // same as { xtype: 'tbfill' }
                {
                    xtype    : 'textfield',
                    name     : 'busca',
                    emptyText: 'Pesquisar'
                }
            ]
        })
    
    
    
    
        var grid = Ext.create('Ext.grid.Panel', {
            //title: 'Materiais', No criar barra de ttulo
            region: 'center',
            store: materialStore,
            columns: [
                { header: 'Nome',  dataIndex: 'nome', editor: 'textfield' },
                { header: 'Descricao', dataIndex: 'descricao', flex: true, editor: 'textfield'},
                { header: 'Preo (Kg)', dataIndex: 'preco_kg', xtype: 'numbercolumn', format: ',0.00',
                    editor:  {
                        type: 'numberfield',
                        renderer: Ext.util.Format.number
                    }
                }
            ],
            plugins: [
                Ext.create('Ext.grid.plugin.CellEditing', {
                    clicksToEdit: 2
                })
            ]
        })
    
    
        Ext.create('Ext.window.Window', {
            title: 'Materiais',
            height: 400,
            width: 600,
            layout: 'border',
            items: [
                Ext.create('Ext.tab.Panel', {
                    region: 'center',
                    items: [
                        Ext.create('Ext.panel.Panel', {
                            layout: 'border',
                            items: [
                                toolbar,
                                grid
                            ]
                        }),
    
    
                        Ext.create('Ext.panel.Panel', {
    
    
                        })
                    ]
                })
            ]
        }).show();

  2. What I needed was just put the proxy definition on the model. It works now. I could even delete the api definition.

    Thanks mitchellsimoens.

  3. #2
    Sencha User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,183
    Answers
    3987
    Vote Rating
    1442
      0  

    Default

    You are using api on the store but a url on the proxy (an old proxy name also). Those I'm sure are conflicting, you should just use api on the proxy.
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

  4. #3
    Sencha User
    Join Date
    Jan 2012
    Posts
    2
    Answers
    1
    Vote Rating
    0
      0  

    Default Solved

    What I needed was just put the proxy definition on the model. It works now. I could even delete the api definition.

    Thanks mitchellsimoens.

Tags for this Thread

Posting Permissions

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