[CLOSED] Batch Update with MVC

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] Batch Update with MVC

    I see a BatchUpdate (non mvc) example. i see a Save WebServices example (closer to mvc).

    However, i dont see a Batch Save example with MVC (persist happens in the controller).

    From what i understand from docs, to use the Batch save, we must use a DirectEvent. I would have expected to use a SyncParameter with Store.getChangedData() but that didnt work. Only works with the DirectEvent.

    I need to use the Batch since all our code is based on the 1.7 stuff and we need the transactional support of all/nothing.

    That being said, how can update the store to remove the dirty flags from the controller? I am on MVC in a controller so i have no access to the store object. I would need to store the data, send it back and then update it manually? Is there a better solution?

    I thought the ConfirmationList was a great solution. In my sample below, i have a standard grid that has a batch save to a controller. saveFunc was the original code but that doesnt seem to work anymore since the data param must be explicit now.

    Also, what is the purpose of the API Sync if i submit via a DirectEvent button?

    <%@ Page Language="C#" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Employee Profile</title>
        <script type="text/javascript">
    
    
            var saveFunc = function (obj) {
                Ext.net.Mask.show();
    
    
                var grid = Ext.getCmp("GridPanel2");
    
    
                grid.getStore().sync();
    
    
            };
    
    
        </script>
    </head>
    <body>
        <form id="Form4" runat="server">
            <ext:ResourceManager ID="ResourceManager" runat="server">
                <Listeners> 
                    <BeforeAjaxRequest Handler="Ext.net.Mask.show();" />             
                    <AjaxRequestComplete Handler="Ext.net.Mask.hide();" />         
                    <AjaxRequestException Handler="Ext.net.Mask.hide();" />         
                </Listeners> 
            </ext:ResourceManager>
    
    
            <ext:Viewport ID="Viewport1" runat="server" AutoScroll="True" Layout="FitLayout">          
                <Items>
                    <ext:GridPanel 
                        ID="GridPanel2" 
                        runat="server" 
                        Title="Summary" 
                        AutoScroll="true">
                        <Store>
                            <ext:Store ID="Store3" 
                                runat="server"               
                                WarningOnDirty="false"
                                RemoteSort="false">
                                <Proxy>
                                    <ext:AjaxProxy  Url="/ta/XXX/AAA/" >
                                        <API Sync="/ta/XXX/BBB/"   />
                                        <Reader>
                                            <ext:JsonReader IDProperty="id" RootProperty="data" TotalProperty="total" />
                                        </Reader>
                                        <Writer>
                                            <ext:JsonWriter Encode="true" RootProperty="data"  />
                                        </Writer>
                                    </ext:AjaxProxy>
                                </Proxy>
                                <Parameters>
                                    <ext:StoreParameter Name="test" Value="false" Mode="Value" />
                                </Parameters>
                                <Model>
                                    <ext:Model ID="Model1" runat="server">
                                        <Fields>
                                            <ext:ModelField Name="id" Type="Int"/>
                                            <ext:ModelField Name="accountAmount" Type="Float" />                        
                                        </Fields>
                                    </ext:Model>
                                </Model>
                            </ext:Store>
                        </Store>
                        <ColumnModel ID="ColumnModel7" runat="server">
                            <Columns>
                                <ext:Column ID="Column2" runat="server" Text="id" Width="90" DataIndex="id" />
                                <ext:Column ID="Column3" runat="server" Text="Actual" Width="140" DataIndex="accountAmount">
                                    <Renderer Fn="change" />
                                    <Editor>
                                        <ext:TextField ID="txtData" runat="server">
                                        </ext:TextField>
                                    </Editor>
                                </ext:Column>
                            </Columns>
                        </ColumnModel>
                        <Plugins>
                            <ext:CellEditing ID="CellEditing1" ClicksToEdit="1" runat="server" >
                            </ext:CellEditing>
                        </Plugins>
                        <SelectionModel>
                            <ext:RowSelectionModel ID="RowSelection5" runat="server" Mode="Single"/>
                        </SelectionModel>
                        <BottomBar>
                            <ext:Toolbar ID="ToolbarUpdate" runat="server">
                                <Items>
                                    <ext:Toolbar ID="ToolbarButtons" runat="server">
                                        <Items>
                                            <ext:Button ID="Button1" runat="server" Text="Sync" Icon="Disk">
                                                <DirectEvents> 
                                                    <Click 
                                                        Url="/ta/XXX/YYY" 
                                                        Timeout="60000"
                                                        CleanRequest="true" 
                                                        Before="return #{Store3}.isDirty();"
                                                        Method="POST"
                                                        Failure="Ext.Msg.show({
                                                            title:   'Error',
                                                            msg:     result.message || result.errorMessage,
                                                            buttons: Ext.Msg.OK,
                                                            icon:    Ext.MessageBox.ERROR
                                                        });">
                                                        <EventMask MinDelay="250" />
                                                        <ExtraParams> 
                                                            <ext:Parameter Name="data" Value="#{Store3}.getChangedData()" Mode="Raw" Encode="true" />
                                                        </ExtraParams> 
                                                    </Click>    
                                                </DirectEvents> 
                                            </ext:Button>
                                            <ext:Button ID="ButtonsaveFunc" runat="server" Text="Save" Icon="Disk">
                                                <Listeners>
                                                    <Click Handler="saveFunc(this);"  />
                                                </Listeners>
                                                        
                                            </ext:Button>
    
    
                                        </Items>
                                    </ext:Toolbar>
                                </Items>
                            </ext:Toolbar>
                        </BottomBar>
                        <View>
                            <ext:GridView ID="GridView1" runat="server" StripeRows="true" />
                        </View>
                    </ext:GridPanel>     
                </Items>
            </ext:Viewport>
        </form>
    </body>
    </html>
    Thanks,
    /Z
    Last edited by Daniil; Aug 17, 2015 at 6:23 PM. Reason: [CLOSED]
  2. #2
    Hello @Z,

    I am on MVC in a controller so i have no access to the store object.
    In MVC I would try to replace a real Store instance (yes, which we have no access to) with a proxy:
    var store = X.GetCmp<Store>("Store id");
    With that proxy you can call server side methods which generates JavaScript code for a response.

    Also, what is the purpose of the API Sync if i submit via a DirectEvent button?
    Under "submit via DirectEvent" do you mean using a Store's .getChangedData() method? If so, I think API Sync is not used at all in this case. API Sync is meant to be only used with a Store's
    .sync()
    method.
  3. #3
    ok. i did create the proxy and i called store.getById(item.id).Commit()

    However, since it is a proxy object (no link to real store), isnt it empty so the getById return null

    Assuming it is valid....now what do i do with it :)

    My controller returns a StoreResult so i tried to set the store to the Data but i get this exception (see pic) when it returns.

    ResourceManager is a read only property of Store so i cant set it.

    Thanks,
    /Z
    Attached Thumbnails Click image for larger version. 

Name:	Untitled.png 
Views:	67 
Size:	29.7 KB 
ID:	24141  
    Last edited by Z; Aug 12, 2015 at 3:29 AM.
  4. #4
    The server side store.GetById(item.id).Commit() only produces a JavaScript code that is sent to client for execution. It doesn't need a link to a real data. But it is meant that a record will be found on client.

    This example demonstrates that the method doesn't fail on server side. But yes, it fails on client side because there is no Store at all.

    So, does your code fail on server or client?

    Example
    <%@ Page Language="C#" %>
    
    <script runat="server">
        protected void Test(object sender, DirectEventArgs e)
        {
            var store = X.GetCmp<Store>("Store1");
    
            store.GetById("someId").Commit();
        }
    </script>
    
    <!DOCTYPE html>
    <html>
    <head runat="server">
        <title>Ext.NET v3 Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
    
            <ext:Button runat="server" Text="Test GetById" OnDirectClick="Test" />
        </form>
    </body>
    </html>
  5. #5
    In the MVC service side. it doesnt fail per se.


    I can make this call in controller without error:
            var store = X.GetCmp<Store>("Store1");
            store.GetById("someId").Commit();

    But now that i did.... how can i return it to the aspx???


    My method uses a Ext.Net.MVC.StoreResult


    public Ext.Net.MVC.StoreResult BBBBB () {
           var store = X.GetCmp<Store>("Store1");
           store.GetById("someId").Commit();
    
    
        Ext.Net.MVC.StoreResult res = new Ext.Net.MVC.StoreResult();
        res.data = store;
        return res;
    }

    The above code doesnt work properly. how can i return the store JS code to the frontend so it is executed properly to remove the dirty flags??


    Please let me asap as we are stuck.


    Thanks,
    /Z
  6. #6
    Do you use the controller action as an URL of Button's Click DirectEvent?

    If so, you should use a DirectResult.

    Example
    public ActionResult Sync()
    {
        var store = X.GetCmp<Store>("Store1");
        store.GetById("someId").Commit();
    
        return this.Direct();
    }
  7. #7
    I will send you a full Solution example (trimmed down) via email. I prefer not to post the entire solution (sample) here since it is off our code base but you can post any solution snippets for everyone to use.

    /Z
  8. #8
    For references - the test project has been posted here.
    http://forums.ext.net/showthread.php...l=1#post273991

    Thank you for the test project.

    I am not sure why you didn't follow the recommendation in this post. Could you, please, clarify?
    http://forums.ext.net/showthread.php...l=1#post273957

    How can I get the changed records to sync properly
    Please see the HandleChanges controller action in this example.
    http://mvc.ext.net/#/GridPanel_Update/Batch
  9. #9
    Because it generates a compile error on my main project. works in the demo one i sent... This is really weird.

    return this.Direct();
    /Z
  10. #10
    Because it generates a compile error on my main project.
    Please share any details about the error.
Page 1 of 2 12 LastLast

Similar Threads

  1. [CLOSED] Batch Update Issue
    By shaileshsakaria in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Apr 03, 2013, 7:08 AM
  2. [CLOSED] GridPanel Batch Update does not send data
    By chrish in forum 2.x Legacy Premium Help
    Replies: 11
    Last Post: Feb 18, 2013, 3:38 AM
  3. Replies: 1
    Last Post: Feb 17, 2013, 3:49 PM
  4. Batch Update
    By shaileshsakaria in forum 2.x Help
    Replies: 1
    Last Post: Jan 18, 2013, 4:17 PM
  5. [2.1] GridPanelFor Batch Update
    By millenovanta in forum 2.x Help
    Replies: 20
    Last Post: Dec 26, 2012, 12:27 PM

Posting Permissions