1. #1
    Ext JS Premium Member
    Join Date
    Mar 2007
    Location
    IL, USA
    Posts
    141
    Vote Rating
    0
    tookoo is on a distinguished road

      0  

    Default How to send records of grid (in XML format) back to server?

    How to send records of grid (in XML format) back to server?


    I am trying to send records inside a editable grid back to the server. I know I can use Ext.util.JSON.encode() to convert them into JSON format, but how can I send them back in XML format? (If possible, using the same format with the XML loaded by Ext.data.XMLReader). Does Ext provide some functions like that? Thanks.

  2. #2
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,483
    Vote Rating
    34
    Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    Code:
    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 + ">";
        }
    });
    That adds an asXml method to the Record class so that you can serialize the modified Records from your Store, and post them back to your server.

  3. #3
    Ext User
    Join Date
    Mar 2007
    Posts
    36
    Vote Rating
    0
    TheRebelGriz is on a distinguished road

      0  

    Default Usage

    Usage


    Yo Animal,

    What is the usage for your code?

    I keep getting 'asXML is not a function' error:

    Thanks!

    Some of the stuff I've tried:
    grid.store.getAt(0).asXml;
    grid.store.getAt(0).asXml();
    grid.store.getAt(0).asXml(0);
    grid.store.asXML(0);

    //SingleSlectionModel
    gAttrs.getSelectionModel().getSelected().asXml;
    gAttrs.getSelectionModel().getSelected().asXml();
    gAttrs.getSelectionModel().getSelected().asXml(0);

    rec = gAttrs.getSelectionModel().getSelected();
    rec.asXml;
    rec.asXml();
    rec.asXml(0);

  4. #4
    Ext User
    Join Date
    Mar 2007
    Posts
    34
    Vote Rating
    0
    zaps is on a distinguished road

      0  

    Default


    how to read entire gridl ?

  5. #5
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,483
    Vote Rating
    34
    Animal has a spectacular aura about Animal has a spectacular aura about

      0  

  6. #6
    Ext User
    Join Date
    May 2007
    Posts
    48
    Vote Rating
    0
    ntulip is on a distinguished road

      0  

    Lightbulb Where was this when I needed it?

    Where was this when I needed it?


    Quote Originally Posted by Animal View Post
    Code:
    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 + ">";
        }
    });
    That adds an asXml method to the Record class so that you can serialize the modified Records from your Store, and post them back to your server.
    I went through hell last night trying to do this and why this thread never came up in my search? I don't know. But I got it done the hard way.

    Animal - Possible you could influence the developers to include this as part of Ext.util.JSON?

  7. #7
    Ext User
    Join Date
    Mar 2007
    Location
    Boston
    Posts
    349
    Vote Rating
    0
    sjivan is on a distinguished road

      0  

    Default


    You should probably escape special characters when constructing xml what way.

    Sanjiv

  8. #8
    Ext User
    Join Date
    Aug 2007
    Posts
    6
    Vote Rating
    0
    Jim Chen is on a distinguished road

      0  

    Default It's very useful

    It's very useful


    Thank you in advance ,Animal .
    but i find a little thing :
    in xmlReader:
    PHP Code:
    var myReader = new Ext.data.XmlReader({
       
    totalRecords"results"// The element which contains the total dataset size (optional)
       
    record:"row",        // The repeated element which contains row information
       
    id"id"                 // The element within the row that provides an ID for the record (optional)
    }, Employee); 
    but in jsonreader , there is no "rs.recore " but only "rs.root" :
    PHP Code:
    var myReader = new Ext.data.JsonReader({
        
    totalProperty"results",    // The property which contains the total dataset size (optional)
        
    root"rows",                // The property which contains an Array of row objects
        
    id"id"                     // The property within each row object that provides an ID for the record (optional)
    }, Employee); 

    so, i change your code "rs.record" to "rs.root" with jsonReader .
    BTW,Can you tell more about "store.reader.meta" ,Thanks a lot.
    Last edited by Jim Chen; 19 Nov 2007 at 11:49 PM. Reason: modify the code

  9. #9

    Default form toXML() method

    form toXML() method


    Hi guys, found this post while looking for ways to post my form as XML back to the server. Here is something Im using to serialise the whole form, its blunt but does the job:

    // Override Ext.form.BasicForm to add Serialization functionality
    Ext.override(Ext.form.BasicForm, {
    toXml : function() {
    var _xml = '<ResultSet>\n<Result>\n';
    var _values = this.getValues();
    for (var prop in _values) {
    _xml+= String.format('<{0}>{1}</{0}>\n',prop, _values[prop]);
    };
    _xml += '</Result>\n</ResultSet>';
    return _xml;
    }
    });

  10. #10

    Default to use it

    to use it


    In order to use this, when you have instantiated a form panel try this:

    alert(myFormPanel.getForm().toXML());

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar