PDA

View Full Version : Form submission results displayed into a grid



shinkenno
23 Jun 2010, 2:37 AM
Hi,

I have a form to query a back-end database.


var SearchPanel = new Ext.FormPanel({
id: 'search-form',
margins: '0 5 0 0',
frame: true,
bodyStyle: 'padding: 5px 5px 5px 5px;background: transparent;',

url: 'search_db.php',

items: [{
xtype:'fieldset',
id: 'code',
title: 'Session code',
autoHeight:true,
defaultType: 'textfield',
items :[{
xtype: 'textfield',
fieldLabel: 'Session code',
width: 120,
name: 'sessioncode',
allowBlank: false,
emptyText: 'Session code here',
}]
}],
buttons: [{
text: 'Search',
handler: function(){
SearchPanel.getForm().submit({

success: function(form, action) {

// Get the result from form submission

// Store it in a data store

// Define grid reader
...

// Define column model
...

// Define view
...

// Print new window with the panel

},
failure: function(form, action) {
//Ext.Msg.alert('Failure');
}
});
}
},{
text: 'Reset',
handler: function(){
SearchPanel.getForm().reset();
}
}]
});

This form contains one field, which is the parameter of my query. The url script returns the query result as a json object (visible correctly in FireBug) like:


{"success": true, "rows":[{"dstart":"2010-06-23","tstart":"18:00:00","dend":"2010-06-24","tend":"18:00:00","name":"rdv79","status":"TO PROCEED","liveurl":"http:\/\/toto.com/index.php?session=rdv79"}]}


I want to store this result and display it into a grid, but I am a little bit lost, especially with these 2 points:

* How can I get the form answer from my php script in a right format to store it ?

* Which proxy should I have to use in my store definition ?

Thanks for your answers !

Condor
23 Jun 2010, 2:46 AM
Use:

success: function(form, action){
grid.getStore().loadData(action.result);
}
(assuming you've setup your store reader to read the returned data)

shinkenno
23 Jun 2010, 5:53 AM
It works ! Thanks Condor !

shinkenno
24 Jun 2010, 12:53 AM
By the way Condor, could you tell me what should I modify/add in order to support paging in this case ?
Thanks !

Condor
24 Jun 2010, 1:07 AM
Local or remote paging?

For local paging you only need to replace your grid store with a PagingStore user extension.

shinkenno
24 Jun 2010, 4:59 AM
Local or remote paging?
Since my store is loaded with the result of my form, can I still use the remote paging ?
What is the most relevent method in my case ?


For local paging you only need to replace your grid store with a PagingStore user extension.

Great ! It works perfectely ! This is just what I need.
Thanks a lot for this perfect extension !

shinkenno
20 Jul 2010, 4:50 AM
Hi again,

I have the followig issue with this store.

1/ I show a window which contains my forms

2/ I submit the form. Data is loaded into store thanks to the code:

SessionGridPanel.getStore().loadData(action.result);

This works the 1st time the window is shown.

3/ I close the window (in fact, I just hide it).

4/ I re-open the window and search for something. I get this message in firebug:

SessionGridPanel.getStore() is null
Is something special hapening when the window is hidden ?

You can test this at http://iya09-ivs.obs.u-bordeaux1.fr/ivslive/
Click on top search button "Session", then search by "Code" with the code "eur*" (without the quotes)

Thanks !

Condor
20 Jul 2010, 6:43 AM
Are you sure you are not destroying the window and/or the store.

shinkenno
20 Jul 2010, 7:15 AM
Yes, that was it ! I was using the function close like this

SessionGridWin.close();

I thought that, since I declared the window with the closeAction: 'hide' property, the window will only be hidden. And apparently not ! :-?
The window and the store were destroyed in the operation. So I just replaced close() by hide()...

SessionGridWin.hide();
Et voilą !

Thanks Condor for showing me the way (once again) =D>