PDA

View Full Version : From grid to FormPanel



jorgeluislay
24 Aug 2012, 3:24 AM
Hi!

I am trying to set a Listener in Grid so after selecting one Record should get some data and send it to the form.

But not from the store of the grid. This data is a new one in xml.

Hier the listener of my grid:


listeners: {
rowselect: function(sm, row, rec) {

Ext.Ajax.request({
disableCaching : false,
url: 'form.xml',
method: 'GET',
reader: allStoreReader,
loadMask:true,
autoLoad: true,
remoteSort: true,
success: function(result, request) {
Ext.getCmp('form').getForm().loadRecord(result.data.items);
}
});

}
}

But this doesnt work. Please help, im working with this issue for about some days, i will also be glad to have hints if possible

jorgeluislay
24 Aug 2012, 5:38 AM
With this:

Ext.getCmp('form').getForm().loadRecord(rec);

Would be possible te get the records into the form if they are coming directly from the grid but i load a new store after selecting a grid record.

jorgeluislay
24 Aug 2012, 6:07 AM
I found a solution for this thread. Of course if someone else has something better, i woul be glad to hear :)



listeners: {
rowselect: function(sm, row, rec) {

Ext.Ajax.request({
disableCaching : false,
url: 'form.xml',
method: 'GET',
loadMask:true,
autoLoad: true,
remoteSort: true,
success: function(result, request) {
var text = result.responseText;

try { // code for IE
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = "true";
xmlDoc.loadXML(text);
}catch(error) { // code for Mozilla, Firefox, Opera, etc.
try {
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(text,"text/xml");
}catch(error) {
alert(error.message + "Data converting failed !");
return;
}
var storeReader = new Ext.data.XmlReader({
record : 'contact'
}, [
{name: 'first', mapping:'name/first'}, // custom mapping
{name: 'last', mapping:'name/last'},
'company', 'email', 'state',
{name: 'dob', type:'date', dateFormat:'m/d/Y'} // custom data types
]);

var myStore = new Ext.data.Store({
data: xmlDoc,
loadMask: true,
method:'GET',
reader: storeReader,
remoteSort: true,
autoLoad: true
});


Ext.getCmp('form').getForm().loadRecord(myStore.data.items[row]);
console.log(myStore.data.items[row]);
}
});

}
}

so the response in text would be translated to xml. after that loaded in the store where i read it and then i send the single items to my form. ~o)