Deba
Deba

Reputation: 63

how to get array of objects from store in extjs 4.2 and send it to server side?

Hiii all, I am using Extjs 4.2 data grid and i have a requirement to convert my 'store' into json array and send that to server side(i.e java).

This is my model.

Ext.define('Writer.Document',{
    extend: 'Ext.data.Model',
    fields: ['id', 'name', 'notes', 'Type', 'date']
});

and my store (which contains list of objects) is

var store = Ext.create('Ext.data.Store', {
model: 'Writer.Document',
autoLoad: true,
proxy: {
    type: 'ajax',            
    url : 'findPatientRecordAction',
    reader: {
        type: 'json',
        successProperty: 'success',
        root: 'prognosis',
        messageProperty: 'message'
    }                       
    fields: ['id','name', 'date', 'notes' , 'Type'],
},
});

So while submitting the values in the grid at a time i require a ist object in my server side . So I need to send JSON Array from client side.

Can anyone please help me out here how to make a JSONArray object from my store and send to Server side???

Regards:Dev

Upvotes: 2

Views: 10062

Answers (1)

Reimius
Reimius

Reputation: 5712

Here's a simple example of how to do what you want:

function sendGridData(){

    var sendDataArray = [];
    store.each(function(record){
        var recordArray = [
            record.get("id"),
            record.get("name"),
            record.get("date"),
            record.get("notes"),
            record.get("Type")
        ];
        sendDataArray.push(recordArray);
    });

    Ext.Ajax.request({
        url: "your_url_here.jsp",
        success: function(response, opts){
            //?
        },
        failure: function(response, opts) {
            alert("server-side failure with status code " + response.status);
        },
        params: {
            grid_data: Ext.encode(sendDataArray);
        }
    });
}

Upvotes: 5

Related Questions