PDA

View Full Version : is there anyway I can extract the data in Grid table into XML format



Supersuper
21 May 2007, 7:04 AM
Hi, I have some data in the grid table, I wonder is it possible to get those data in the table and store it into XML file?

jsakalos
21 May 2007, 7:06 AM
I'd guess it would need some coding to iterate through store and reconstruct the xml.

BTW, why would you need it?

Supersuper
21 May 2007, 7:14 AM
do you have any example about that? or is it possible to get the data into xml format?

jsakalos
21 May 2007, 7:34 AM
do you have any example about that? or is it possible to get the data into xml format?

Re 1: No, I don't have example. I don't consider it useful as if data came from server in xml why would I need to take it from store and reconstruct? I can use xml directly, no? Further, I don't have access to the local filesystem from javascript anyway, so what would I do with the xml? Send it back to server?

The only reason here would be to send updated xml back to server, after the user has modified the data. There is a plenty of examples in the forum on how to do this.

Re 2: Yes, (almost) everything is possible in Ext. ;)

Animal
21 May 2007, 7:48 AM
Try adding this to your overrides:



Ext.override(Ext.data.Record, {
asXml : function(rowIndex) {
var r = this.store.reader.meta;
var elName = r.record;
var result = "<" + elName + " id=\"" + this.id + "\">";
this.fields.each(function(f) {
result += "<" + f.name;
if (f.type && f.type !== "auto") {
result += " type=\"" + f.type + "\"";
}
result += ">" + this.get(f.name) + "</" + f.name + ">";
}, this);
return result + "</" + elName + ">";
}
});


It allows you to convert the Records in your Store to XML strings.

Perhaps it should be added to Ext as a standard part of the Record class?

Supersuper
21 May 2007, 9:34 AM
I wonder how to this override by the function which is not in the Ext.onReady();



Try adding this to your overrides:



Ext.override(Ext.data.Record, {
asXml : function(rowIndex) {
var r = this.store.reader.meta;
var elName = r.record;
var result = "<" + elName + " id=\"" + this.id + "\">";
this.fields.each(function(f) {
result += "<" + f.name;
if (f.type && f.type !== "auto") {
result += " type=\"" + f.type + "\"";
}
result += ">" + this.get(f.name) + "</" + f.name + ">";
}, this);
return result + "</" + elName + ">";
}
});


It allows you to convert the Records in your Store to XML strings.

Perhaps it should be added to Ext as a standard part of the Record class?