1. #1
    Ext User
    Join Date
    Jun 2008
    Posts
    7
    Vote Rating
    0
    existenz is on a distinguished road

      0  

    Default send store through post

    send store through post


    Hello. I'm new with extjs and I want to ask you something.
    I have created an EditorGridPanel in a FormPanel and I need to send the data from the grid through post. In that FormPanel I have created a ComboBox. When I'm printing the $_POST in php I can see the ComboBox but not the GridPanel. Can anyone help me please?

  2. #2
    Ext User
    Join Date
    Jul 2007
    Location
    Florida
    Posts
    9,996
    Vote Rating
    5
    mjlecomte will become famous soon enough mjlecomte will become famous soon enough

      0  

    Default


    I believe you have to collect the data in the grid manually, it won't be included with the form automatically. There should be several threads about this if you search around, it's a fairly frequent question.

  3. #3
    Ext User jeffypop13's Avatar
    Join Date
    Mar 2008
    Posts
    38
    Vote Rating
    0
    jeffypop13 is on a distinguished road

      0  

    Default


    We've solved this by adding listeners to the store. You can listen for load, update, add, and remove events. Each time an event is fired, we copy the contents of the store to a hidden form field. When the form is posted, you have the current state of the store on the server. Here's how we copy the store to the hidden control:

    Code:
    function CopyStoreToForm(store){
      var json = '';
      store.each(function(store){
          json += Ext.util.JSON.encode(store.data) + ',';
      });
      json = json.substring(0, json.length - 1);
      Ext.getDom('GridData').value = json
    };

  4. #4
    Ext User
    Join Date
    Jun 2008
    Posts
    7
    Vote Rating
    0
    existenz is on a distinguished road

      0  

    Default


    thanks!!
    I've tried that before. I've tried alert(Ext.util.JSON.encode(store.data)) to see if this works and I got this error(firebug): "too much recursion". After that I've abandoned this idea.
    But your function works just fine.

  5. #5
    Ext JS Premium Member syscobra's Avatar
    Join Date
    Nov 2007
    Location
    Venezuela
    Posts
    140
    Vote Rating
    0
    syscobra is on a distinguished road

      0  

    Default


    Thanks, for this too.

    I used the function on the handler of the form and it worked well too withous listeners o every event. Just sent the current store on the form submit button.
    Javier Rincón aka SysCobra

  6. #6
    Ext User
    Join Date
    Jul 2008
    Posts
    8
    Vote Rating
    0
    steve.kerrison is on a distinguished road

      0  

    Default


    Just ran into this issue myself.

    I've tweaked the function slightly:
    Code:
    var jsonEncodeStore = function(store){
        var json = '[';
        store.each(function(store){
            json += Ext.util.JSON.encode(store.data) + ',';
        });
        json = json.substring(0, json.length - 1);
        json += ']';
        return json;
    };
    Works well. Thanks.

  7. #7
    Ext User
    Join Date
    Aug 2008
    Posts
    4
    Vote Rating
    0
    ext2000 is on a distinguished road

      0  

    Default


    I am a true newbie to JSON, but I found out that the json your function generated is just not a well-formed JSON according to the production on json.org. Your function generates strings in the form of:

    [ {...}, {...} , ... ]

    But a well-formed JSON string should be:

    "{mydata: [ {...}, {...} , ... ] }

    Currently I found I could not handle the JSON string your function generated, instead I have to manually add the bold part above to make my JSON parser work correctly. Can you tell me what you do with the JSON generated by your function? Can you JSON parser accept it? Thanks!



    Quote Originally Posted by steve.kerrison View Post
    Just ran into this issue myself.

    I've tweaked the function slightly:
    Code:
    var jsonEncodeStore = function(store){
        var json = '[';
        store.each(function(store){
            json += Ext.util.JSON.encode(store.data) + ',';
        });
        json = json.substring(0, json.length - 1);
        json += ']';
        return json;
    };
    Works well. Thanks.

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

      0  

    Default


    JSON is just a javcascript literal.

    [ {...} ]

    is an Array literal. Ae mentioned just a few lines down at json.org.

  9. #9
    Ext User
    Join Date
    Jul 2008
    Posts
    8
    Vote Rating
    0
    steve.kerrison is on a distinguished road

      0  

    Default


    Quote Originally Posted by ext2000 View Post
    Currently I found I could not handle the JSON string your function generated, instead I have to manually add the bold part above to make my JSON parser work correctly. Can you tell me what you do with the JSON generated by your function? Can you JSON parser accept it? Thanks!
    As Animal said, it should be a valid array literal.

    My JSON gets POSTed to a PHP script and uses the json_decode function of PHP5 to turn it into an associative array.

  10. #10
    Ext User dbeatle123's Avatar
    Join Date
    Mar 2009
    Posts
    25
    Vote Rating
    1
    dbeatle123 is on a distinguished road

      0  

    Default Another Solution

    Another Solution


    Hi all,

    Here is a solution that avoids the looping concats (which scares a PERL guy like me).

    Code:
    var jsonEncodeStore = function(store){
        var data_array = [];
        store.each(function(store){
            data_array.push(store.data);
        });
        return Ext.util.JSON.encode(data_array);
    };