1. #1
    Sencha User
    Join Date
    Feb 2012
    Posts
    219
    Answers
    10
    Vote Rating
    5
    webfriend13 is on a distinguished road

      0  

    Default Answered: How to post data using ExtJs Store

    Answered: How to post data using ExtJs Store


    Hi all,

    Please look at the following store:

    Code:
    var store = new Ext.create('Ext.data.ArrayStore', {
                        id: 'store',
                        autoLoad: false,
                        buffered: true,
                        pageSize: 50,
                        fields: resultFields,
                        remoteSort: true,
                        proxy: {
                            type: 'ajax',
                            url: '/url/results',
                            jsonData: jsonStr,
                            actionMethods: {
                                create: 'POST',
                                read: 'POST',
                                update: 'POST',
                                destroy: 'POST'
                            },
                            extraParams: {
                                  userName: 'fid'
                            },
                            reader: {
                                root: 'data',
                                totalProperty: 'totalCount'
                            }
                        }
                    });
    I am not able to "POST" the data using Extjs Store. I am able to see the extra params which i am sending but not the data I am trying to send using jsonData config. The same code works when i use Ext.Ajax.request.

    Please note: I dont want to send data available in my store. I want to send data available in 'jsonStr' variable declared somewhere in my program


    Code:
    //with following code I am able to post data to server
    Ext.Ajax.request({
                 url: '/url/results',
                method: 'POST',
                //Send the query as the message body
                jsonData: jsonStr,
                params: {
                       userName: 'fid'
                }
    });
    Please provide your suggestions.

  2. I used following link and used it to POST the data.

    http://www.sencha.com/forum/showthre...t-POST-xmlData

    Following is my code.

    Code:
    
    Ext.define('Ext.ux.data.proxy.Ajax', {                    requires: ['Ext.util.MixedCollection', 'Ext.Ajax'],                    extend: 'Ext.data.proxy.Ajax',                    doRequest: function (operation, callback, scope) {                        var writer = this.getWriter(),                        request = this.buildRequest(operation, callback, scope);                        if (operation.allowWrite()) {                            request = writer.write(request);                        }                        Ext.apply(request, {                            jsonData: jsonStr,                            headers: this.headers,                            timeout: this.timeout,                            scope: this,                            callback: this.createRequestCallback(request, operation, callback, scope),                            method: this.getMethod(request),                            disableCaching: false // explicitly set it to false, ServerProxy handles caching                        });                        Ext.Ajax.request(request);                        return request;                    }                });                store = new Ext.create('Ext.data.ArrayStore', {                    id: 'store',                    autoLoad: false,                    buffered: true,                    pageSize: 100,                    fields: resultFields,                    remoteSort: true,                    proxy: Ext.create(Ext.ux.data.proxy.Ajax, {                        type: 'ajax',                        url: '/mdx/results',                        actionMethods: {                            create: 'POST',                            read: 'POST',                            update: 'POST',                            destroy: 'POST'                        },                        extraParams: {                              connName: PA.common.Connection.getConnName()                        },                        reader: {                            root: 'data',                            type: 'array',                            totalProperty: 'totalCount'                        }                    }) //End of proxy                });                store.guaranteeRange(0, 99);                //create the group feature to group the headers                var groupingFeature = Ext.create('Ext.grid.feature.Grouping', {                    groupHeaderTpl: 'Group: {name} ({rows.length})',                    startCollapsed: true                });                //Prepare the grid                var grid = Ext.create('Ext.grid.Panel', {                    id: 'resultgrid',                    store: store,                    enableColumnHide: false,                    enableColumnMove: false,                    columnLines: true,                    columns: resultColumns,                    viewConfig: {                        stripeRows: true                    },                    features: [groupingFeature]                });

  3. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,081
    Answers
    675
    Vote Rating
    467
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    You could send the data as a param?

    params: {
    jsonData: jsonStr
    }

    Regards,
    Scott.

  4. #3
    Sencha User
    Join Date
    Feb 2012
    Posts
    219
    Answers
    10
    Vote Rating
    5
    webfriend13 is on a distinguished road

      0  

    Default


    I used following link and used it to POST the data.

    http://www.sencha.com/forum/showthre...t-POST-xmlData

    Following is my code.

    Code:
    
    Ext.define('Ext.ux.data.proxy.Ajax', {                    requires: ['Ext.util.MixedCollection', 'Ext.Ajax'],                    extend: 'Ext.data.proxy.Ajax',                    doRequest: function (operation, callback, scope) {                        var writer = this.getWriter(),                        request = this.buildRequest(operation, callback, scope);                        if (operation.allowWrite()) {                            request = writer.write(request);                        }                        Ext.apply(request, {                            jsonData: jsonStr,                            headers: this.headers,                            timeout: this.timeout,                            scope: this,                            callback: this.createRequestCallback(request, operation, callback, scope),                            method: this.getMethod(request),                            disableCaching: false // explicitly set it to false, ServerProxy handles caching                        });                        Ext.Ajax.request(request);                        return request;                    }                });                store = new Ext.create('Ext.data.ArrayStore', {                    id: 'store',                    autoLoad: false,                    buffered: true,                    pageSize: 100,                    fields: resultFields,                    remoteSort: true,                    proxy: Ext.create(Ext.ux.data.proxy.Ajax, {                        type: 'ajax',                        url: '/mdx/results',                        actionMethods: {                            create: 'POST',                            read: 'POST',                            update: 'POST',                            destroy: 'POST'                        },                        extraParams: {                              connName: PA.common.Connection.getConnName()                        },                        reader: {                            root: 'data',                            type: 'array',                            totalProperty: 'totalCount'                        }                    }) //End of proxy                });                store.guaranteeRange(0, 99);                //create the group feature to group the headers                var groupingFeature = Ext.create('Ext.grid.feature.Grouping', {                    groupHeaderTpl: 'Group: {name} ({rows.length})',                    startCollapsed: true                });                //Prepare the grid                var grid = Ext.create('Ext.grid.Panel', {                    id: 'resultgrid',                    store: store,                    enableColumnHide: false,                    enableColumnMove: false,                    columnLines: true,                    columns: resultColumns,                    viewConfig: {                        stripeRows: true                    },                    features: [groupingFeature]                });

  5. #4
    Sencha User
    Join Date
    Feb 2013
    Location
    NZ
    Posts
    74
    Answers
    5
    Vote Rating
    0
    mazhar.shaikh is on a distinguished road

      0  

    Default


    If I have my code looking as follows, how would I use your suggestion:

    Code:
    var grid = Ext.getCmp('reviewPicklistGrid');
    var store = Ext.getStore('GeneratePicklist');
    var selection = grid.getSelectionModel().getSelection();
    if (selection.length > 0){
        var jsonData = Ext.encode(Ext.Array.pluck(selection, 'data'));
        store.proxy.url = PickList.globals.url + 'Orders/PrintPicklist'; // MY URL
        store.sync();
        console.log(jsonData);
    }
    Thanks

Thread Participants: 2