1. #1
    Sencha User
    Join Date
    Apr 2012
    Posts
    1
    Vote Rating
    1
    reuadism is on a distinguished road

      1  

    Default Submit Data from GridPanel with CheckboxSelectionModel

    Hi everyone,

    i'am relatively new to ExtJS and Javascript so i'am not really familar to best pratices by far.

    I have a simple data.Store like this
    Code:
    var store = new Ext.data.Store({
    url : '/servletURLtoGetData', reader : new Ext.data.XmlReader({
    /* config of my reader */
    })
    });
    Furthermore I have a ColumnModel and a CheckboxSelectionModel.
    Code:
    var sm = new Ext.grid.CheckboxSelectionModel({
    });
    
    var cm = new Ext.grid.ColumnModel({
    columns : [{
    column1
    }, {
    column2
    }, {
    column3
    }, sm]
    });
    The GridPanel which uses these components looks like this:
    Code:
    var gp = new Ext.grid.GridPanel({
    store : store, cm : cm, sm : sm, width : 561, height : 400
    });
    Now I added the GridPanel to my Panel:
    Code:
    var fp = new Ext.Panel({
    renderTo : 'view',
    cls : 'left-right-buttons',
    frame : 'true', layout : {
    type : 'table', columns : 1
    },
    width : 573,
    height : 485,
    items : [lHead, lText, gp, bNext]
    });
    What I want to do is get all checked items from the GrinPanel and send all the releated data to my servlet. Preferred as Xml.

    I allready managed to send the data via JSON, but I didn't find a encode method for Xml like it is available for JSON.

    My JSON solution looks like this:
    Code:
    var bNext = new Ext.Button({
    text : 'Next',
    width : 75,
    cls : 'buttonRight',
    handler : function() {
    var records = sm.getSelections(); var choices = [];
    for (var i = 0; i < records.length; i++) {
    choices.push(records[i].data);
    }
    var choicesJSON = Ext.util.JSON.encode(choices);
    var conn = new Ext.data.Connection();
    conn.request({
    url : 'servletURLtoPostData',
    params : {
    action : 'post',
    data : choicesJSON
    },
    success : function() {
    },
    failure : function() {
    }
    });
    }
    });


    Is there any possibility to send the data as Xml?
    I hope you understand what I want to do


    Thanks in advance,
    reuadism.

  2. #2
    Sencha User
    Join Date
    Jan 2011
    Posts
    549
    Vote Rating
    54
    willigogs is a jewel in the rough willigogs is a jewel in the rough willigogs is a jewel in the rough

      0  

    Default

    To send and receive data as XML, I believe you would need to use the xmlstore, possibly using xmlreader and xmlwriters:
    http://docs.sencha.com/ext-js/3-4/#!....data.XmlStore

  3. #3
    Sencha User sword-it's Avatar
    Join Date
    May 2012
    Location
    Istanbul
    Posts
    1,334
    Vote Rating
    87
    sword-it is just really nice sword-it is just really nice sword-it is just really nice sword-it is just really nice

      0  

    Default you can do it in server side

    Hi,

    It would be better to convert JSON data to XML in the server side.

    You can post your JSON object as a string using below method:

    Code:
    Ext.Ajax.request({
    ....
    params: { json: Ext.util.JSON.encode({ values: { name: "Jack" }}) }
    ....
    }); It will be converted as: <values>
    <name>Jack</name>
    </values>
    OR

    try to google for a js code which converts JSON to XML as a string.

    Regards.
    sword-it.com, Sencha Developer House in Turkey - Istanbul University Technopark Suite 204.

Thread Participants: 2