[CLOSED] How to clear store

  1. #1

    [CLOSED] How to clear store

    I would like to clear the contents of a json store and populate with a new blank record for editing in a FormPanel. There is a clearmeta method, but I can't find any documentation on what it is or how to use it. Am I on the wrong track?

    Thanks.
  2. #2

    RE: [CLOSED] How to clear store

    Hi,

    A store has*RemoveAll method (if you don't have it then please update from SVN).*
    To add blank record use AddRecord function of store.


    Also there are client side functions removeAll and addRecord if you need to perform it on client side instead server side
  3. #3

    RE: [CLOSED] How to clear store



    That's great. I updated Coolite on my system and I have the RemoveAll now. It is not performingproperly, so I must be missing something.

    The store starts out populated with one record, and I want the user to click the "Add new" button to clear the contents of the store and populate it with a new, mostly blank, record.

    This is what I am doing, but it gives me a syntax error in the statement "return eval("("+json+')');" in some dynamically generated code. Below are the relevant code snippets. What am I missing? Thanks.

    <?xml:namespace prefix = ext /><ext:Store id=storeOneDenial runat="server">
    </ext:Store>
    
    <ext:Store runat="server">    protected void addNew(object sender, AjaxEventArgs e)
        {
            
            storeOneDenial.RemoveAll();
            IDictionary<string, string> recordData = new Dictionary<string, string>();
            recordData.Add("Primary_ID","");
            recordData.Add("Statement_ID", "New Statement");
            recordData.Add("IsActive", "");
            recordData.Add("Applies_All", "");
            recordData.Add("GroupID", "");
            recordData.Add("Effective_On", "");
            recordData.Add("Statement", "");
            recordData.Add("Appliesto", "");
            recordData.Add("status", "");
            storeOneDenial.AddRecord(recordData);
            Panel0.Reload();
            Panel0.Expand();
        }</ext:Store>
    
    <ext:Store runat="server"></script></ext:Store>
    
    <ext:Store runat="server">
    </ext:Store><ext:Store runat="server">


    <ext:Store ID="storeOneDenial" runat="server">
         <Reader>
         <ext:JsonReader>
                <Fields>
                    <ext:RecordField Name="Primary_ID" Type="Int" />
                    <ext:RecordField Name="Statement_ID" Type="String" />
                    <ext:RecordField Name="IsActive" Type="Boolean" />
                    <ext:RecordField Name="Applies_All" Type="Int" />
                    <ext:RecordField Name="GroupID" Type="Int" />
                    <ext:RecordField Name="Effective_On" Type="Date" />
                    <ext:RecordField Name="Statement" Type="String" />
                    <ext:RecordField Name="Appliesto" Type="String" />
                    <ext:RecordField Name="status" Type="String" />
                </Fields>
         </ext:JsonReader>
         </Reader>
        <Listeners>
            <DataChanged Handler="var record = this.getAt(0)||{};#{Panel0}.getForm().loadRecord(record);" />
        </Listeners>
    </ext:Store>
                    <ext:ToolbarButton ID="AddButton" runat="server" Text="Add new" StandOut="true" Icon="Add">
                        <AjaxEvents>
                            <Click OnEvent="addNew">
                                <EventMask ShowMask="true" />
                            </Click>
                        </AjaxEvents>
                    </ext:ToolbarButton>
    </ext:Store>
  4. #4

    RE: [CLOSED] How to clear store

    It appears that the variable "json" in the statement "return eval("("+json+')');" contains HTML. I'm not sure what that means. Thanks.
  5. #5

    RE: [CLOSED] How to clear store

    Hi,

    In your case it is better to rebind the store with a blank record. Please see the following sample
    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Collections.Generic"%>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" 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></title>
    
        <script runat="server">
           protected void Page_Load(object sender, EventArgs e)
           {
               if (!Ext.IsAjaxRequest)
               {
                   storeOneDenial.DataSource = new List<object>
                                                   {
                                                       new {GroupID = 1, Statement_ID = 1, IsActive = true, Effective_On = new DateTime(2009,1,1), Statement = "Statement1"},
                                                       new {GroupID = 2, Statement_ID = 2, IsActive = true, Effective_On = new DateTime(2009,1,2), Statement = "Statement2"},
                                                       new {GroupID = 3, Statement_ID = 3, IsActive = true, Effective_On = new DateTime(2009,1,3), Statement = "Statement3"}
                                                   };
                   storeOneDenial.DataBind();
               }
           }
    
           protected void AddNew(object sender, AjaxEventArgs e)
           {
               storeOneDenial.DataSource = new List<object>
                                                   {
                                                       new {GroupID = "", Statement_ID = "New Statement", IsActive = "", Effective_On = "", Statement = ""}
                                                   };
               storeOneDenial.DataBind();
           }
      </script>
    
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ScriptManager ID="ScriptManager1" runat="server" />
            
            <ext:Store ID="storeOneDenial" runat="server">
                <Reader>
                    <ext:JsonReader>
                        <Fields>
                            <ext:RecordField Name="Primary_ID" Type="Int" />
                            <ext:RecordField Name="Statement_ID" Type="String" />
                            <ext:RecordField Name="IsActive" Type="Boolean" />
                            <ext:RecordField Name="Applies_All" Type="Int" />
                            <ext:RecordField Name="GroupID" Type="Int" />
                            <ext:RecordField Name="Effective_On" Type="Date" />
                            <ext:RecordField Name="Statement" Type="String" />
                            <ext:RecordField Name="Appliesto" Type="String" />
                            <ext:RecordField Name="status" Type="String" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>
                <Listeners>
                    <DataChanged Handler="var record = this.getAt(0)||{};#{Panel0}.getForm().loadRecord(record);" />
                </Listeners>
            </ext:Store>
            
            <ext:FormPanel ID="Panel0" Icon="Page" Title="Denial Statement Detail" Collapsible="true"
                runat="server" Border="false" AutoHeight="true" BodyStyle="padding:6px;"
                Cls="grayPanel">
                <Body>
                    <ext:TableLayout ID="colLayout_TopForm" Columns="2" runat="server">
                        <ext:Cell CellCls="cellAlignTop">
                            <ext:Panel ID="Panel2" Border="false" BodyStyle="padding: 5px 5px 5px 5px;" runat="server">
                                <Body>
                                    <ext:FormLayout ID="formLayoutDenial" LabelWidth="200" LabelStyle="text-align: right; font-weight: bold;"
                                        runat="server">
                                        <ext:Anchor>
                                            <ext:TextField ID="txtGroupID" FieldLabel="Client" DataIndex="GroupID" runat="server">
                                            </ext:TextField>
                                        </ext:Anchor>
                                        <ext:Anchor>
                                            <ext:Checkbox ID="txtInactive" FieldLabel="Inactive" DataIndex="IsActive" runat="server">
                                            </ext:Checkbox>
                                        </ext:Anchor>
                                        <ext:Anchor>
                                            <ext:TextField ID="txtStatementID" FieldLabel="Identifier" DataIndex="Statement_ID"
                                                runat="server">
                                            </ext:TextField>
                                        </ext:Anchor>
                                        <ext:Anchor>
                                            <ext:DateField ID="txtEffective" FieldLabel="Effective" DataIndex="Effective_On"
                                                Type="Date" DateFormat="Y-m-d" runat="server">
                                            </ext:DateField>
                                        </ext:Anchor>
                                        <ext:Anchor>
                                            <ext:HtmlEditor ID="txtStatement" FieldLabel="Statement" DataIndex="Statement" Height="200" AutoWidth="true"
                                                runat="server" />
                                        </ext:Anchor>
                                    </ext:FormLayout>
                                </Body>
                            </ext:Panel>
                        </ext:Cell>
                    </ext:TableLayout>
                </Body>
                <TopBar>
                    <ext:PagingToolbar ID="Pager1" runat="server" PageSize="1" StoreID="storeOneDenial"
                        DisplayInfo="true" />
                </TopBar>
                <BottomBar>
                    <ext:Toolbar ID="Toolbar1" CtCls="CssTextLeft" runat="server">
                        <Items>
                            <ext:ToolbarButton ID="Button2" runat="server" Text="Cancel" StandOut="true" Icon="Cancel" />
                            <ext:ToolbarButton ID="ToolbarButton1" runat="server" Text="Add New" StandOut="true">
                                <AjaxEvents>
                                    <Click OnEvent="AddNew"></Click>
                                </AjaxEvents>
                            </ext:ToolbarButton>
                        </Items>
                    </ext:Toolbar>
                </BottomBar>
            </ext:FormPanel>
        </form>
    </body>
    </html>
  6. #6

    RE: [CLOSED] How to clear store

    That solves it. Thank again, Vlad.

Similar Threads

  1. [CLOSED] store id clear
    By speedstepmem4 in forum 1.x Legacy Premium Help
    Replies: 18
    Last Post: Apr 06, 2011, 7:15 PM
  2. Store and clear datasource
    By glenh in forum 1.x Help
    Replies: 0
    Last Post: Oct 20, 2010, 5:18 AM
  3. [CLOSED] Clear Store IsDirty
    By fondant in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Nov 23, 2009, 11:10 AM
  4. [CLOSED] How to clear the store and update a paging toolbar
    By tdracz in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Nov 19, 2009, 12:22 PM
  5. Clear Store binded to ObjectDataSource
    By juanpablo.belli@huddle.com.ar in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 02, 2009, 4:03 AM

Posting Permissions