[CLOSED] reload store and grid on client side

  1. #1

    [CLOSED] reload store and grid on client side

    How can I reload store on client side?

    When I submit something, it call ajax to update database.
    So store and grid need to be updated right after updating database.

    Why following is not working?

    <script type="text/javascript">
        function updateChat(msg) {
            $.ajax({
                type: "post",
                url: '<%= Url.Action("UpdateChat", "Mshw")%>',
                data: { msg: msg },
                success: function (ret) {
                    Ext.Msg.alert('Submit', ret);
                },
                error: function () {
                    Ext.MessageBox.alert('Error', 'Error detected during updating msg.');
                }
            });
    
            var store = Ext.getCmp("chatStore");
            store.reload();
        }
    </script>
    I'm mainly using MVC and JQuery.
    Last edited by Daniil; Aug 15, 2011 at 4:02 PM. Reason: [CLOSED]
  2. #2
    Hi,
    Why following is not working?
    Please always provide more details. How exactly does it not work?

    I think a JS error occurs here:
    var store = Ext.getCmp("chatStore");store.reload();
    .getCmp() doesn't return a store instance. Please use Ext.getCmp() for Ext.Component and its inheritors. A Store is not an Ext.Component inheritor.

    Generally speaking, you can access a store (and any widgets as well) by its client id:
    chatStore.reload();
  3. #3
    <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    </asp:Content>
    
    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">   
    
        <div class="content-body">
            <table width="97%" border="0">
                <tr>
                    <td style="width: 60%;">
                    </td>
                    <td>
                        <ext:Panel runat="server" Width="400" Height="275">
                            <Items>
                                <ext:BorderLayout runat="server">
                                    <North>
                                        <ext:GridPanel runat="server" ID="chatGrid" ClientIDMode="Static" Width="400" Height="200" Border="false" >
                                            <Store>
                                                <ext:Store runat="server">
                                                    <Proxy>
                                                        <ext:HttpProxy Method="POST" Url='<%# Url.Action("GetAllChat", "Mshw") %>' AutoDataBind="true" Json="true" />
                                                    </Proxy>
                                                    <Reader>
                                                        <ext:JsonReader Root="items" TotalProperty="total">
                                                            <Fields>
                                                                <ext:RecordField Name="name" Type="String" />
                                                                <ext:RecordField Name="msg" Type="String" />
                                                                <ext:RecordField Name="date" Type="String" />
                                                            </Fields>
                                                        </ext:JsonReader>
                                                    </Reader>
                                                </ext:Store>
                                            </Store>
                                            <ColumnModel>
                                                <Columns>                            
                                                    <ext:Column Header="Name" DataIndex="name" Sortable="false" Width="180" />
                                                    <ext:Column Header="Time" DataIndex="date" Sortable="false" Width="190"  />
                                                </Columns>
                                            </ColumnModel>
                                            <View>
                                                <ext:GridView ID="GridView1" runat="server" EnableRowBody="true">
                                                    <GetRowClass Handler="rowParams.body = '<p>' + record.data.msg + '</p>'; return 'x-grid3-row-expanded';" />                    
                                                </ext:GridView>        
                                            </View>
                                            <LoadMask ShowMask="true" /> 
                                        </ext:GridPanel>
                                    </North>
                                    <Center>
                                        <ext:FormPanel ID="formMsg" runat="server" ButtonAlign="Right" Padding="5" Height="75">
                                            <Items>
                                                <ext:TextField ID="txtMsg" runat="server" AnchorHorizontal="95%" FieldLabel="Leave a message" ></ext:TextField>
                                            </Items>
                                            <Buttons>
                                                <ext:Button ID="btnMsgSubmit" runat="server" Text="Submit">
                                                    <Listeners>                                                    
                                                        <Click Handler="updateChat(#{txtMsg}.getValue());" />
                                                    </Listeners>
                                                </ext:Button>
                                            </Buttons>
                                        </ext:FormPanel>
                                    </Center>
                                </ext:BorderLayout>
                            </Items>
                        </ext:Panel>
    
                        
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                    </td>
                </tr>
            </table>
        </div>
        
    <script type="text/javascript">
        function updateChat(msg) {
            $.ajax({
                type: "post",
                url: '<%= Url.Action("UpdateChat", "Mshw")%>',
                data: { msg: msg },
                success: function (ret) {
                    Ext.Msg.alert('Submit', ret);
                },
                error: function () {
                    Ext.MessageBox.alert('Error', 'Error detected during updating msg.');
                }
            });
        };
    </script>
    </asp:Content>
    I want to update database and refresh the grid when submit button click.
    Any idea?
  4. #4
    Update database? Do you mean saving client side changes?

    Please see this example (UpdateHttpProxy) from Ext.Net.MVC.Demo:
    [Ext.Net.MVC root]\Ext.Net.MVC.Demo\Views\Customer\CustomerList.aspx
  5. #5
    MSSQL Database. I want to ADD something to database then show it on the grid on button click
  6. #6
    Just call reload method to retrieve data

    1.
    store.reload({params:{msg:'test'}});
    2.
    public AjaxStoreResult GetMessages(string msg)
    {
         if(msg != null)
         {
            // add message to DB
         }
         
         // retrieve data from DB and return it to the client
         return new AjaxStoreResult(...);
    }

Similar Threads

  1. Replies: 3
    Last Post: Dec 26, 2011, 1:32 PM
  2. [CLOSED] Get Grid Height on client after direct event reload
    By rthiney in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jan 20, 2011, 7:04 PM
  3. Replies: 1
    Last Post: Dec 01, 2010, 5:14 PM
  4. Create Simple Store and Bind to Grid Client-Side?
    By Tbaseflug in forum 1.x Help
    Replies: 4
    Last Post: Oct 30, 2009, 5:27 PM
  5. Replies: 0
    Last Post: Sep 17, 2009, 8:04 AM

Posting Permissions