[CLOSED] When updating a grid via a store update proxy is it possible to return additional script to run?

  1. #1

    [CLOSED] When updating a grid via a store update proxy is it possible to return additional script to run?

    Hi,

    I have been looking at this example here:
    https://examples1.ext.net/#/GridPane.../HandlerUsing/

    I like how you can do this:
    <UpdateProxy>
        <ext:HttpWriteProxy Method="POST" Url="../../Shared/SuppliersSave.ashx" />
    </UpdateProxy>
    That seems almost exactly what we need, as many of our grids are generated on demand so we can't send updates of our grid to code behind/post back.

    However, in our scenarios, sometimes editing one column can change the values of other columns (through complex business logic).

    Our ashx update implementation calls some custom business logic components where we have the ability to get those updated rows from our storage system automatically as a return value of the update call.

    I can easily convert those updated records into a format that the Store object works with so it would be nice to somehow just return them in that same ashx request, but I can't see how/if that is possible?

    If it is not, is the only option to make a second ajax request to refresh the store? So, where you have this:

    <ext:Button runat="server" Text="Save" Icon="Disk">
        <Listeners>
            <Click Handler="#{GridPanel1}.save();" />
        </Listeners>
    </ext:Button>
    Would I have to do something just after save, such as this:

    <ext:Button runat="server" Text="Save" Icon="Disk">
        <Listeners>
            <Click Handler="#{GridPanel1}.save(); #{GridPanel1}.reload();" />
        </Listeners>
    </ext:Button>
    If the save() is asynchronous, then would reload execute too quickly and if so, do I just hook into the store's onSave event (or whatever it is called) and do a reload then?
    Last edited by Daniil; Jun 10, 2011 at 6:45 PM. Reason: [CLOSED]
  2. #2
    Hi,

    Unfortunately no, HttpProxy expects appointed response (success, message, confirmation data)
    Try to return your information in the message and parse/decode it
  3. #3
    Thanks for the prompt reply - good idea with decoding the message; that is just a string so I could put JSON into it etc?

    I could even maybe try to manually return a DirectResponse:

    Contrived example:

    message = new DirectResponse(UpdateSavedRecords().ToScript(RenderMode.AddTo, context.Request["container"])).Return();
    and invoke something like that manually perhaps?
  4. #4
    Quote Originally Posted by Vladimir View Post
    Try to return your information in the message and parse/decode it
    Hi Vladimir,

    Where can I find the response? I tried to use a CommitDone listener on the Store, but when I log the arguments to the function, I see the store and an empty object.

    However, when I inspect firebug, I see my custom messages as well as committed records coming back.

    This is just the JSON response (cleaned up)

    {
        success: true,
        message: "{\"419\":\"My custom update message or data 0\",\"420\":\"My custom update message or data 1\",\"424\":\"My custom update message or data 2\",\"429\":\"My custom update message or data 3\"}",
        data: {
            confirm: [{
                s: true,
                oldId: "419",
                newId: "419"
            }, {
                s: true,
                oldId: "420",
                newId: "420"
            }, {
                s: true,
                oldId: "424",
                newId: "424"
            }, {
                s: true,
                oldId: "429",
                newId: "429"
            }]
        }
    }
    In the store object, I can see a responseSaveData property that has (as the name suggests!) just the data property, but I can't see the message anywhere to do anything with it...

    It is a bit tricky to create a custom working example with my code base, but here's the update ashx in essence:

    using System;
    using System.Collections.Generic;
    using System.Web;
    using Ext.Net;
    
    namespace Examples
    {
        public class UpdateHandler : IHttpHandler //, IRequiresSessionState
        {
            private const string RecordKey = "_Id";
    
            private Response _storeResponse;
    
            public void ProcessRequest(HttpContext context)
            {
                context.Response.ContentType = "application/json";
    
                _storeResponse = new Response(true);
    
                try
                {
                    var dataHandler = new StoreDataHandler(context);
                    ChangeRecords<Dictionary<string, string>> data = dataHandler.ObjectData<Dictionary<string, string>>();
                    ConfirmationList confirmationList = dataHandler.BuildConfirmationList(RecordKey);
    
                    var allConfirmationMessages = new ChangeRecords<Dictionary<string, string>>();
                    var confirmationMessages = new Dictionary<string, string>();
    
                    int i = 0;
                    foreach (Dictionary<string, string> documents in data.Updated)
                    {
    
                        // process documents to update
                        confirmationList[documents[RecordKey]].ConfirmRecord();
    
                        confirmationMessages.Add(documents[RecordKey], "My custom update message or data " + i++);
                    }
                    allConfirmationMessages.Updated = new List<Dictionary<string, string>>(new[] { confirmationMessages });
    
                    var response = new StoreResponseData { Confirmation = confirmationList };
    
                    _storeResponse.Data = response.ToString();
                    _storeResponse.Message = JSON.Serialize(confirmationMessages);
                }
                catch (Exception e)
                {
                    _storeResponse.Success = false;
                    _storeResponse.Message = e.Message;
                }
    
                _storeResponse.Write();
            }
    
            public bool IsReusable
            {
                get { return false; }
            }
        }
    }
    And here is a bit of code to bind it all:

    Store1.UpdateProxy.Add(new HttpWriteProxy { Method = HttpMethod.POST, Url = "UpdateHandler.ashx "});
    Store1.Listeners.CommitDone.Fn = "Examples.CommitSucceeded";
    
    GridPanel1.TopBar[0].Items.Insert(0, new Ext.Net.Button {
        Text = "Submit Changes",
        Listeners = { Click = { Handler = "#{" + GridPanel.ID + "}.save();" } }
    });
    And the script I use to just try and verify on the commit:

    <script type="text/javascript">
        Ext.ns("CustomGridHandlers");
    
        CustomGridHandlers.CommitSucceeded = function() {
            console.log(arguments);
        }
    </script>
    Any suggestions on how to get hold of the message on a successful commit? Maybe I'm looking at the wrong listener?
  5. #5
    Hi,

    Use Save handler of Store
    <Save Handler="alert(arg.message);" />
  6. #6
    Woah... that was a bit too easy :) Dunno how I missed that.

    Many thanks for that!

    [I think you can mark this as Solved for now.]

Similar Threads

  1. [CLOSED] Store Filter Not Updating Grid
    By peter.campbell in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: May 23, 2012, 3:47 PM
  2. Replies: 1
    Last Post: Dec 22, 2011, 6:17 AM
  3. Replies: 5
    Last Post: Nov 29, 2011, 7:22 PM
  4. [CLOSED] return html server response instead of just long extjs script!
    By webclouder in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: May 17, 2011, 8:38 AM
  5. [CLOSED] Using a update proxy on a store with params?
    By Riset in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Dec 02, 2009, 12:21 PM

Posting Permissions