Results 1 to 3 of 3

Thread: Data Writers not sending data!

  1. #1
    Sencha User
    Join Date
    Apr 2011
    Posts
    10

    Exclamation Data Writers not sending data!

    Hello All,
    I'm trying to create a Grid with a row editor that will work with a REST service I have written. My problem is that my REST service is not recieving any data! I've tried both the Json, and Xml writers. Both access the correct URI ( /api/rest/documents/24 for example ). However, neither seems to be sending any parameters! I was previously working with ExtJS 3, and had a custom writer that just sent a set of keys in the standard POST/GET key=data style, but I don't have the know-how to rewrite it for ExtJS 4. Any idea what I am doing wrong?

    Thanks in advance,
    Kyle

    Here is my code:
    Code:
    Ext.require(['Ext.data.*', 'Ext.grid.*']);
    
    Ext.define('Document', {
        extend: 'Ext.data.Model',
        fields: [
            {
                name: 'id',
                type: 'int',
                useNull: true,
            },
            {
                name: 'name',
                type: 'text',
                useNull: 'true',
            },
        ]
    });
                                                                                            
    Ext.onReady(function(){
        var writer = new Ext.data.writer.Json();
    
        var reader = new Ext.data.JsonReader({
                    type: 'json',
                    root: 'items',
                    totalProperty  : 'total',
                    successProperty: 'success'                    
        });
    
        var store = Ext.create('Ext.data.Store', {
            autoLoad: true,
            autoSync: true,
            remoteSort: true,
            model: 'Document',
            proxy: {
                type: 'rest',
                url: '/api/rest/documents',
                headers: {
                      'Accept' : 'application/json'
                },
                
                reader: reader,
                
                writer: writer,
            }
        });
    
        var bbar = new Ext.PagingToolbar({
            //pageSize: 10,
            store: store
        });
    
        var rowEditing = Ext.create('Ext.grid.plugin.RowEditing');
    
        var grid = Ext.create('Ext.grid.Panel', {
            renderTo: 'documents-grid',
            plugins: [rowEditing],
            width: 400,
            height: 300,
            frame: true,
            title: 'Documents',
            store: store,
            iconCls: 'icon-user',
            bbar: bbar,
            columns: [
                {
                    text: 'ID',
                    width: 40,
                    sortable: true,
                    dataIndex: 'id',
                    renderer: function(v){
                        if (Ext.isEmpty(v)) {
                            v = ' '
                        }
                        return v;
                    }
                }, 
                {
                    text: 'Name',
                    flex: 1,
                    sortable: true,
                    dataIndex: 'name',
                    field: {
                        xtype: 'textfield'
                    }
                }, 
            ],
            dockedItems: [{
                xtype: 'toolbar',
                items: [{
                    text: 'Add',
                    iconCls: 'icon-add',
                    handler: function(){
                        // empty record
                        store.insert(0, new Document());
                        rowEditing.startEdit(0, 0);
                    }
                }, '-', {
                    text: 'Delete',
                    iconCls: 'icon-delete',
                    handler: function(){
                        var selection = grid.getView().getSelectionModel().getSelection()[0];
                        if (selection) {
                            store.remove(selection);
                        }
                    }
                }]
            }]
        });
    });

  2. #2

    Default

    Using Firebug, check the request being made. It may be sending the params, except not in traditional key=val format.

    I know that the AJAX Proxy, by default (and by an UNOVERRIDABLE DEFAULT NONETHELESS), encodes data as JSON for the request. Perhaps the REST Proxy does the same.

    If you find any way to override how a proxy encodes its data (not just sort/group/filter params, but actual model data), PLEASE PLEASE PLEASE let me know!

  3. #3
    Sencha User
    Join Date
    Apr 2011
    Posts
    10

    Default Key/Val Writer

    In the end, I was able to recreate my simple writer in Ext JS 4. Here is the code. I'm pretty sure this will break if a key is used multiple times. I'm not sure how to handle that issue.

    Code:
    /**
     * @class Ext.data.writer.Simple
     * @extends Ext.data.writer.Writer
     * @ignore
     */
    Ext.define('BizWerks.data.writer.Simple', {
        extend: 'Ext.data.writer.Writer',
        alternateClassName: 'BizWerks.data.SimpleWriter',
        alias: 'writer.bw.simple',
    
        writeRecords: function(request, data) {
            for( d in data ) {
                    for( key in data[d] ) {
                            //This probably needs to be modified to work
                            //with arrays of data larger then 1
                            request.params[key] = data[d][key];
                    }
            }
    
            return request;
        }
    });

Similar Threads

  1. Ajax Requests from Data Writers
    By mcamer in forum Ext 3.x: Help & Discussion
    Replies: 4
    Last Post: 21 Jul 2010, 9:48 AM
  2. Sending data from textfield
    By MalcolmHaslam in forum Ext 3.x: Help & Discussion
    Replies: 2
    Last Post: 2 Jul 2009, 8:09 AM
  3. Sending data
    By oasisjoel in forum Ext 2.x: Help & Discussion
    Replies: 13
    Last Post: 3 May 2009, 6:08 PM
  4. Issue with sending data
    By border9 in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 30 Oct 2008, 8:50 AM
  5. Sending data with AJAX
    By Zolcsi in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 25 Dec 2007, 4:48 AM

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
  •