PDA

View Full Version : How to use a response data in a grid toolbar



filippo.ferrari
30 Nov 2010, 4:06 AM
I've a grid and a toolbar... My grid is loaded with a json store, for debugging I receive in my json from server, out of the root data for my grid, the query dinamically created on server.

Now i want to use it ( my query) client-side like a param inside the action of a button in the grid toolbar...

How to catch a response and re-use it with data not in the root of store data reader?

My Json from server is like this:



{
"root":[{item1},{item2},....],
"query":"SELECT * FROM dual WHERE 0 = 0 ",
"message":"ok",
"risultati":"10",
"risultatitotali":"330"}

Condor
30 Nov 2010, 5:09 AM
You can access the original data as store.reader.jsonData.

ps. You do know that using SQL on the client is highly insecure?

filippo.ferrari
30 Nov 2010, 5:51 AM
This is my button:



{
text: 'Print As You Seen',
xtype: 'button',
id: 'bt-print',
handler: function(){
console.log(this.getStore().reader.jsonData.query);
}
}
Firebug log exactly my query.

I think this is a little insecure but my app. works in an intranet... What do you suggest to perform an "as you seen in the grid" print mechanism, only sending again the same params?

Condor
30 Nov 2010, 5:58 AM
There is an extension that can rerender the grid in a hidden IFRAME so it can be printed, but I recommend creating a PDF or XML on the server from the same data for download (e.g. using a LinkButton).

filippo.ferrari
30 Nov 2010, 6:06 AM
How to retrieve every last params, if i log the store i can see lastOptions.params but there are only "start" and "limit" params?

Condor
30 Nov 2010, 6:13 AM
lastOptions.params don't contain sort, dir and baseParams. You could combine these into the used params.

Another method would be to use a beforeload event handler and store the actual used params.

filippo.ferrari
1 Dec 2010, 12:24 AM
Tanks!

This is great, now:



listeners:{
beforeload: function(store, options){
console.log(options);
}
},
Options contains every sended params, now I can perform a new request to produce a PDF .. ;)

filippo.ferrari
1 Dec 2010, 1:45 AM
A little bonus to this thread: I use this code to concat standard grid params like sort, limit and dir with ux.grid.GridFilters filters.



// In store configuration
listeners:{
beforeload: function(store, options){

printParams = Ext.urlEncode(options.params);
filterGridParams = '&' + Ext.urlEncode(filters.buildQuery(filters.getFilterData()));

if (filterGridParams != '&'){
printParams = printParams + filterGridParams;
}
}
},