Manipulate records returned from HttpProxy before loading GridPanel

  1. #1

    Manipulate records returned from HttpProxy before loading GridPanel

    I have a GridPanel tied to a Store that has an HttpProxy. The HttpProxy is calling a web service to load the Store. The web service is returning a Paging<object>. I am trying to return extra data with it, though, to be stored in a Hidden field on the page (so that I don't have to use Session). I have tried to accomplish this in 2 ways:

    1. I created my own Paging class (MyPaging) that inherited from the Paging class that included an extra IEnumerable property. I couldn't find a way to get to the response on the client side after the data was retrieved from the web service, so I was just pushing an extra IEnumerable that I couldn't figure out how to get to. I need to get to the javascript object(s) returned from this web service.

    2. I added a row to the IEnumerable<object> data within the Paging<object>. After it returned, I could get to the data (via the HttpProxy Load listener, but couldn't prevent the extra row from showing up on the grid. Specifically, a blank row now shows up and the page count is 1 more than it should be. With this approach, I need to find a way to remove the record from the store and populate the grid from the data currently in the store (every load, reload on grid and store hits the web service again).


    Does anyone know a way?
  2. #2

    RE: Manipulate records returned from HttpProxy before loading GridPanel

    Could you use a Ajaxmethod on the client side to download the extra information you need and just store it locally as a javascript variable instead of using the store's request.
  3. #3

    RE: Manipulate records returned from HttpProxy before loading GridPanel

    I found out how to accomplish #2.

    I set the Store load listener in C# in code behind:

    Store1.Listeners.Load.Handler = string.Format("saveOffData(records,{0},{1});", myGridPanel.ClientID, myHidden);
    and I could delete the record from the grid, so that it never showed up:
    function saveOffData(records, myGrid, myHidden) {
        if (records.length > 0 &amp;&amp; records[0].json.MyColumn != undefined) {
            myHidden.setRawValue(records[0].json.MyColumn);
            myGrid.deleteRecord(records[0]);
        }

    Thanks for your input fpw2377. I could have used an AjaxMethod, but I would have still needed to store the data in Session temporarily (inside the httpproxy web service method) in order to get the data on the AjaxMethod call. This way I don't require Session at all.
  4. #4
    Hi,

    Thanks for the idea of subclassing Paging<T>. I was looking to pass more data back from an ashx HttpProxy GET as well. I came across your post and was about to bump it in case the Ext.Net team had an idea or other approaches. In the process of providing an example, I managed to get it to work as I found you could get the additional information off the JSON response off the store.reader.jsonData property.

    Here's how, using this example from the examples explorer:

    https://examples1.ext.net/#/GridPane...rting/Handler/

    And modify the PlantHandler.ashx.cs as follows (very silly/contrived examples!):

    1) Create a subclass of Paging:

    public class MyPaging : Paging<Plant>
    {
        public string ExampleAdditionalData { get; set; }
    
        public Dictionary<string, string> Refinements { get; set; }
    }
    2) In the ashx that returns the JSON serialized plant data, modify it to return MyPaging instead of Paging, e.g:

    Paging<Plant> plants = Plant.PlantsPaging(start, limit, sort, dir, query);
    
    // new bit
    var myPaging = new MyPaging
    {
        Data = plants.Data,
        TotalRecords = plants.TotalRecords,
        ExampleAdditionalData = "text",
        Refinements = new Dictionary<string, string>
        {
            {"key1", "value1"},
            {"key2", "value2"},
            {"key3", "value3"},
            {"key4", "value4"}
        }
    };
    
    // return myPaging instance instead of plants
    context.Response.Write(JSON.Serialize(myPaging));
    3) In the Ext Store definition, add a Load listener to get hold of the new data, e.g.

    <Listeners>
        <Load Fn="Test.StoreLoad" />
    </Listeners>
    and the associated Fn JavaScript (enable Firebug or equivalent to see the console.log output):

    <script type="text/javascript">
        var Test = {};
        
        Test.StoreLoad = function(store, records, params) {
            console.log(store.reader.jsonData);
        }
    </script>
    And the additional data is there in the JsonData...!

    Hope that helps.

Similar Threads

  1. [CLOSED] Problem trying to manipulate image...
    By RCN in forum 2.x Legacy Premium Help
    Replies: 14
    Last Post: Jul 10, 2012, 6:12 PM
  2. Replies: 3
    Last Post: May 09, 2012, 1:51 PM
  3. [CLOSED] Local Paging and loading records via DirectMethods
    By macap in forum 1.x Legacy Premium Help
    Replies: 15
    Last Post: May 31, 2011, 3:28 PM
  4. Replies: 3
    Last Post: Jun 29, 2010, 2:54 PM
  5. GridPanel HttpProxy and RemoteGroup
    By niceguymattx in forum 1.x Help
    Replies: 1
    Last Post: May 20, 2010, 6:38 AM

Posting Permissions