[CLOSED] [1.0] Store adding record

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] [1.0] Store adding record



    Here is the situation.

    I have a store that is on the .aspx page. I add to this store in javascript by creating records for it that a user creates. This store is bound to a GridPanel.

    Two questions.

    1. When I try to access the Items from the GridPanel via CodeBehind. It is returning a Items.Count of 0.
    2. How do I access record information (from codebehind) from the Store?

    Here is a very simplified example of what I am doing.

    .aspx:
    <script language="javascript">
        var Manager = {
            addItem: function() {
                var value = tData.Text;
    
                var tempRecord = Ext.data.Record.create([
                                                { name: 'DataValue' }
                                            ]);
    
               var found = strData.query('DataValue', value, false, false);
    
                if (found.length <= 0) {
                    var record = new tempRecord({ DataValue: value });
                    strData.add(record);
                }
            }
        }
    </script>
    
    <ext:Store ID="strData" runat="server">
        <Reader>
            <ext:JsonReader>
                <Fields>
                    <ext:RecordField Name="DataValue" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
     
    <ext:GridPanel ID="gpGrid" runat="server" StroreID="strData">
        <ColumnModel>
            <ext:Column ColumnID="DataValue" DataIndex="DataValue" Header="Value" />
        </ColumnModel>
    </ext:GridPanel>
    <ext:TextField ID="tData" runat="server" />
    <ext:Button ID="bAdd" runat="server" Text="Add" Icon="Accept">
        <Listeners>
            <Click Handler="Manager.addItem();" />
        </Listeners>
    </ext:Button>
    <ext:Button ID="bDone" runat="server" Text="Done" Icon="Package">
        <DirectEvents>
            <Click OnEvent="bDone_Click" />
        </DirectEvents>
    </ext:Button>
    .aspx.cs:
    protected void bDone_Click(object sender, EventArgs e) {
        // TODO: Want to pull data that was dynamically added to grid/store.  How?
    }
    }
  2. #2

    RE: [CLOSED] [1.0] Store adding record

    Hi,

    You need to use save/submit js functions (save - submit changes only, submit - submit all data)
    The examples explorer contains many example how to save data (for example, see GridPanel/WebService_Connections)

    Here is modified sample
    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Collections.Generic"%>
    
    <%@ 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>Ext.NET Examples</title>
        
        <script runat="server">
            protected void SaveData(object sender, BeforeStoreChangedEventArgs e)
            {
                ChangeRecords<JsonObject> data = e.DataHandler.ObjectData<JsonObject>();
    
                foreach (JsonObject deleted in data.Deleted)
                {
                    // to get value use string indexer
                    //string value = deleted["DataValue"].ToString();
                }
    
                foreach (JsonObject updated in data.Updated)
                {
                   
                }
    
                foreach (JsonObject created in data.Created)
                {
                    
                }
    
                e.Cancel = true;    
            }
            
            protected void SubmitData(object sender, StoreSubmitDataEventArgs e)
            {
                List<JsonObject> data = e.Object<JsonObject>();
            }
        </script>
        
        <script type="text/javascript">
            var Manager = {
                addItem: function() {
                    var value = tData.getValue();
    
                    var found = strData.query('DataValue', value, false, false);
    
                    if (found.length <= 0) {
                        strData.addRecord({ DataValue: value });
                    }
                }
            }
         </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ResourceManager ID="resourceManager1" runat="server">
            </ext:ResourceManager>
    
            <ext:Store ID="strData" runat="server" OnBeforeStoreChanged="SaveData" OnSubmitData="SubmitData" RefreshAfterSaving="None">
                <Reader>
                    <ext:JsonReader>
                        <Fields>
                            <ext:RecordField Name="DataValue" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>
            </ext:Store>
            
            <ext:GridPanel ID="gpGrid" runat="server" StoreID="strData" Height="200">
                <ColumnModel>
                    <Columns>
                        <ext:Column ColumnID="DataValue" DataIndex="DataValue" Header="Value" />
                    </Columns>                
                </ColumnModel>
            </ext:GridPanel>
            
            <ext:TextField ID="tData" runat="server" />
            
            <ext:Button ID="bAdd" runat="server" Text="Add" Icon="Accept">
                <Listeners>
                    <Click Handler="Manager.addItem();" />
                </Listeners>
            </ext:Button>
            
            <ext:Button ID="bDone" runat="server" Text="Save" Icon="Package">
                <Listeners>
                    <Click Handler="#{gpGrid}.save();" />
                </Listeners>
            </ext:Button>
            
             <ext:Button ID="Button1" runat="server" Text="Submit" Icon="Package">
                <Listeners>
                    <Click Handler="#{gpGrid}.submit();" />
                </Listeners>
            </ext:Button>
        
        </form>
    </body>
    </html>
    Please note that by default the grid reloads data after saving (to update ids for new records for example). If you don't want it then set RefreshAfterSaving="None" for the store or use ConfirmationList (see examples in the Examples Explorer)
  3. #3

    RE: [CLOSED] [1.0] Store adding record

    This is leading me in the right direction.

    But, I need to be able to pull from the Store/GridPanel sometime AFTER the user may or may have changed the store.

    Basically, they might be able to update the GridPanel/Store with a new record, however, another button on another panel might need to pull the data from the Store/GridPanel (or a completely different process in code-behind may need to check if the Store/GridPanel has rows in it, or has a certain record in it using DirectMethods).

    I hope I explained this well.
  4. #4

    RE: [CLOSED] [1.0] Store adding record

    Hi,

    Sorry but I did not understand you requirement. Please provide more details
  5. #5

    RE: [CLOSED] [1.0] Store adding record

    Hi,

    If you need to pass store changes with DirectMethod calling then see modified example
    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Collections.Generic"%>
    
    <%@ 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>Ext.NET Examples</title>
        
        <script runat="server">
            protected void SaveData(object sender, BeforeStoreChangedEventArgs e)
            {
                ChangeRecords<JsonObject> data = e.DataHandler.ObjectData<JsonObject>();
    
                foreach (JsonObject deleted in data.Deleted)
                {
                    // to get value use string indexer
                    //string value = deleted["DataValue"].ToString();
                }
    
                foreach (JsonObject updated in data.Updated)
                {
                   
                }
    
                foreach (JsonObject created in data.Created)
                {
                    
                }
    
                e.Cancel = true;    
            }
            
            protected void SubmitData(object sender, StoreSubmitDataEventArgs e)
            {
                List<JsonObject> data = e.Object<JsonObject>();
            }
            
            [DirectMethod]
            public void DirectMethodTest(ChangeRecords<JsonObject> data)
            {
                int i = 0;
            }
            
            
        </script>
        
        <script type="text/javascript">
            var Manager = {
                addItem: function() {
                    var value = tData.getValue();
    
                    var found = strData.query('DataValue', value, false, false);
    
                    if (found.length <= 0) {
                        strData.addRecord({ DataValue: value });
                    }
                },
                
                dMethod : function(){
                    Ext.net.DirectMethods.DirectMethodTest("{"+strData.getChangedData()+"}", {
                        success: function (){
                            strData.commitChanges();
                        }
                    });
                }
            }
         </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ResourceManager ID="resourceManager1" runat="server">
            </ext:ResourceManager>
    
            <ext:Store ID="strData" runat="server" OnBeforeStoreChanged="SaveData" OnSubmitData="SubmitData" RefreshAfterSaving="None">
                <Reader>
                    <ext:JsonReader>
                        <Fields>
                            <ext:RecordField Name="DataValue" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>
            </ext:Store>
            
            <ext:GridPanel ID="gpGrid" runat="server" StoreID="strData" Height="200">
                <ColumnModel>
                    <Columns>
                        <ext:Column ColumnID="DataValue" DataIndex="DataValue" Header="Value" />
                    </Columns>                
                </ColumnModel>
            </ext:GridPanel>
            
            <ext:TextField ID="tData" runat="server" />
            
            <ext:Button ID="bAdd" runat="server" Text="Add" Icon="Accept">
                <Listeners>
                    <Click Handler="Manager.addItem();" />
                </Listeners>
            </ext:Button>
            
            <ext:Button ID="bDone" runat="server" Text="Save" Icon="Package">
                <Listeners>
                    <Click Handler="#{gpGrid}.save();" />
                </Listeners>
            </ext:Button>
            
            <ext:Button ID="Button2" runat="server" Text="Save with DirectMethod" Icon="Accept">
                <Listeners>
                    <Click Handler="Manager.dMethod();" />
                </Listeners>
            </ext:Button>
            
             <ext:Button ID="Button1" runat="server" Text="Submit" Icon="Package">
                <Listeners>
                    <Click Handler="#{gpGrid}.submit();" />
                </Listeners>
            </ext:Button>
        
        </form>
    </body>
    </html>
  6. #6

    RE: [CLOSED] [1.0] Store adding record



    Well, what I need to do is be able to get the data from the Store/GridPanel in the code from a code behind button. See example below.

    Here is an example of a custom usercontrol calling an Event on the main page.

    ... javascript  here on adding record to Store... (see example on previous post) ...
    
    ... Grid/Store here ... (see example on previous post) ...
    
    <myControl:UserControl ID="ctlUserControl" runat="server" OnCustomEvent="ctlUserControl_CustomEvent" />
    protected void ctlUserControl_CustomEvent(object sender, CustomControlEventArgs e)  {
        // TODO:  How do I pull Grid/Store data from here using the example on pervious post?
    
        // Something that I might do in this CustomEvent
        if (recordCount < 1) e.Cancel = true;
    }
    By the way, the event WILL be "fired" in a DirectMethod call from a button. I need the data from the Grid/Store in code behind from a DirectMethod call when the records are created dynamically in javascript.

    I hope this explains it alittle better.
  7. #7

    RE: [CLOSED] [1.0] Store adding record

    Hi,

    I am still unsure what problem do you have. You have data in direct method. Pass that data as you like to any user controls. For example, define data property in the CustomControlEventArgs class and then pass data data with event argument class
  8. #8

    RE: [CLOSED] [1.0] Store adding record



    Can you show a quick example of how you would do that with the UserControl code above?

    Thanks.
  9. #9

    RE: [CLOSED] [1.0] Store adding record

    Hi,

    Please post test example with user control and firing its event
  10. #10

    RE: [CLOSED] [1.0] Store adding record

    Here is a code sample attached of what we're trying to do.
Page 1 of 2 12 LastLast

Similar Threads

  1. [CLOSED] Adding a new grid record
    By adelaney in forum 2.x Legacy Premium Help
    Replies: 8
    Last Post: Jun 06, 2012, 3:14 PM
  2. [CLOSED] Adding New Record at run time
    By jesperhp in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Feb 27, 2012, 12:17 PM
  3. Replies: 16
    Last Post: May 26, 2011, 10:23 PM
  4. [CLOSED] Adding a new Store Record - Not a Record object
    By Steve in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: May 15, 2009, 7:40 AM
  5. Adding one record in a grid
    By nuno_Santos in forum 1.x Help
    Replies: 1
    Last Post: Apr 14, 2009, 5:55 PM

Posting Permissions