[CLOSED] Immediate update of store after update or insert

  1. #1

    [CLOSED] Immediate update of store after update or insert

    Hi,

    I am using a JSON loader in a store connected to an http-handler for load and write operations.
    Is it possible to send the updated/inserted records back to the store within the write request (similar to ID confirmation)?

    Some values are calculated on server side and should be visible in the grid as soon as the data is saved without having to reload the complete store...

    Thanks in advance!

    Bernd
    Last edited by geoffrey.mcgill; Jul 09, 2010 at 9:27 PM.
  2. #2
  3. #3
    Hi,

    not exactly what I am looking for.
    To make it clearer:
    This is the store definition:
    <ext:Store ID="stDnsEntries" runat="server" AutoSave="false" AutoLoad="false" RefreshAfterSaving="None"
            RemotePaging="false" WarningOnDirty="true" PruneModifiedRecords="true" SkipIdForNewRecords="False" UseIdConfirmation="false">
            <Reader>
                <ext:JsonReader IDProperty="Name">
                    <Fields>
                        <ext:RecordField Name="Name"  />
                        <ext:RecordField Name="IPAddress" />
                        <ext:RecordField Name="NewIPAddress" />
                        <ext:RecordField Name="StatusId" Type="Int" DefaultValue="1" />
                        <ext:RecordField Name="Checked" Type="Boolean" DefaultValue="true" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
            <Proxy>
                <ext:HttpProxy Url="~/Handler.ashx" Method="POST" Json="True">
                </ext:HttpProxy>
            </Proxy>
            <UpdateProxy>
                <ext:HttpWriteProxy Url="~/UpdateHandler.ashx" Method="POST" Json="True">
                </ext:HttpWriteProxy>
            </UpdateProxy>
        </ext:Store>
    And this the Handler:

    private void UpdateData(HttpContext context)
            {
                Response sr = new Response(true);
                List<DnsEntry> edited = new List<DnsEntry>();
                try
                {
    
                    StoreDataHandler dataHandler = new StoreDataHandler(context);
                    ChangeRecords<DnsEntry> data = dataHandler.ObjectData<DnsEntry>();
    
                    foreach (DnsEntry entry in data.Deleted)
                    {
                        entry.Delete();
                    }
    
                    foreach (DnsEntry entry in data.Updated)
                    {
                        entry.Verify();
                        entry.Save();
                        edited.Add(entry);
                    }
    
                    foreach (DnsEntry entry in data.Created)
                    {
                        entry.Verify();
                        entry.Save();
                        edited.Add(entry);
                    }
                }
                catch (Exception e)
                {
                    sr.Success = false;
                    sr.Message = e.Message;
                }
               //return a list of all modified objects
                sr.Data = JSON.Serialize(edited); 
                sr.Write();
            }
    My thought was, that if I return the modified objects in the data field of the response, the store would update these records...

    Hope this helps to understand the question.

    Regards

    Bernd
  4. #4
    Hi,

    1. Please updatre from SVN
    2. In http handler build Data response like
    sr.Data = JSON.Serialize(new System.Collections.Generic.List<object> { new { id = 18, CompanyName = "New name" } });
    3. Add the following Save listener to the Store
    <Save Fn="saveHandler" />
    function saveHandler(){
                if(this.responseSaveData){
                    for(var i = 0; i < this.responseSaveData.length; i++){                
                        var entity = this.responseSaveData[i],
                            id = entity["id"],
                            record = this.getById(id);
                            
                        for(var key in entity){
                            if(key != "id"){
                                record.set(key, entity[key]);
                            }                        
                        }
                        
                        record.commit();
                    }
                };
            }
  5. #5
    Thanks very much,

    this solved my problem.
    However the data from the server is not present if submitData() is called. I added the same changes in Ext.NET source:
    this.responseSaveData = o.data || null;
    in finishSubmit function. This works well.

    Also I had to adapt the handler to be able to update inserted records:

    var entity = store.responseSaveData[i],
           id = entity["Name"],
           record = store.getById(id);
           if (!record) {
                 record = store.query('Name', id).first();
           }

Similar Threads

  1. Update/Insert only Modified/New Datagrid Rows
    By jocker_wow in forum 1.x Help
    Replies: 1
    Last Post: Jan 10, 2011, 4:22 PM
  2. GridPanel - Update Firing but not insert
    By Tbaseflug in forum 1.x Help
    Replies: 0
    Last Post: Jul 22, 2010, 12:23 AM
  3. Replies: 0
    Last Post: Jun 10, 2010, 1:18 AM
  4. Replies: 2
    Last Post: Dec 22, 2008, 5:50 PM
  5. LINQ - Insert/Update
    By Tbaseflug in forum 1.x Help
    Replies: 1
    Last Post: Dec 22, 2008, 2:13 PM

Posting Permissions