PDA

View Full Version : setting proxy to Grouping Store



ramana438
12 Feb 2014, 5:29 AM
Hi all,

In this code to load data into GroupingStore I am using data option which will call getData method to get information from a REST client. This is fine. But I wanted to set proxy to Grouping store so that the Grid's refresh function will work properly. I tried to set proxy but ajaxReader's meta tag. The JSON data to the Grouping store will be as shown below


{
"metaData":{
"totalProperty":"total",
"root":"data",
"successProperty":"success",
"fields":[
{
"name":"dur",
"type":"number"
},
{
"name":"part name,
"type":"string"
},
{
"name":"price",
"type":"number"
},
{
"name":"enterdate",
"type":"timestamp"
}
]
},
"success":true,
"total":20,
"data":[
{
"ENTRY_DATE":"Mar 20, 2014 12:10:00 AM",
"Partner Name":"xxx2232",
"Price":56929.39905492754,
"Duration":0
},
{
"ENTRY_DATE":"Mar 20, 2014 12:20:00 AM",
"Partner Name":"xxxx012",
"Price":16868.04338214273,
"Duration":0
},
]
}




var getData = function(url) {
console.log("inside getData method");
var request = ((window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"));
request.open("GET", url, false); //<-- false makes it a synchronous request!
request.send(null);
console.log("response text :" + request.responseText);
return Ext.decode(request.responseText);
};
var ajaxReader = new Ext.data.JsonReader();
var storeRawData = new Ext.data.GroupingStore({
reader: ajaxReader,

data: getData('http://localhost:8080/<app_name>/rest/alarm/rawdata/sample')
});

var dynamicGridColumns = []; // Array to store dynamically created columns

// create the column model dynamically by iterating through the “fields” of the response JSON.
for (var i = 0, len = ajaxReader.meta.fields.length; i < len; i++) { // Iterating through fields to create dynamic columns
var field = ajaxReader.meta.fields[i];
//console.log(field.name);

var gridColumn = {}; // new column object will be created dynamically for each field to be displayed
if(field.type == "timestamp") { // Setting format and xtype if the field is timestamp
gridColumn['xtype'] = "datecolumn";

gridColumn['format'] = "Y-m-d H:i:s";
}
gridColumn['header'] = field.name; // Field name will be setting as column header

gridColumn['width'] = 150;

gridColumn['sortable'] = true;

gridColumn['dataIndex'] = field.name;

gridColumn['menuDisabled'] = true;

dynamicGridColumns.push(gridColumn); // Using this dynamic columns to display the GRID.
}


Any help would be grateful.

Thanks in Advance.

mitchellsimoens
12 Feb 2014, 10:22 AM
There are many things here that aren't good.

First, you are using a sync request, you shouldn't have to do this, you should change your thinking to be asynchronous instead of synchronous.

Second, is this for Ext 3 or 4? I ask because there isn't an Ext.data.GroupingStore class in Ext 4.

ramana438
19 Feb 2014, 1:49 AM
Thank you very much for your reply mitchellsimoens. I was able to solve that with asynchronous way by using JsonStore.