When updated GridPanel.GetStore().DataSource, the page doesn't show the store

  1. #1

    When updated GridPanel.GetStore().DataSource, the page doesn't show the store

    When I opened the site the first time, it work normally.
    Click image for larger version. 

Name:	{QSDDC8RO7G96TN{`C`9ZQP.png 
Views:	52 
Size:	18.0 KB 
ID:	24779
    But when I Clicked Save Button, the GridPanel doesn't showed anything.
    Click image for larger version. 

Name:	N5T%V9U_AKEJL)[G(9PC@SV.png 
Views:	21 
Size:	6.8 KB 
ID:	24780
    It did already set store's DataSource, because I have used visual studio to debug to see the result.

    Here's the code:
    Click image for larger version. 

Name:	N@Q{I8{Q%ZI01X58EYPQ~98.png 
Views:	29 
Size:	14.9 KB 
ID:	24782

    Click image for larger version. 

Name:	LI}5CG$V787WGAF_KIN19NU.png 
Views:	29 
Size:	17.4 KB 
ID:	24781

    The save Button's event:
    Click image for larger version. 

Name:	YJ8519NQAGQON8GWXP$)$HM.png 
Views:	18 
Size:	4.7 KB 
ID:	24783
    Last edited by eko; Nov 18, 2016 at 3:01 AM.
  2. #2
    Hello @eko!

    Can you, instead of taking pictures of the code, paste them in the page and wrap the code blocks in [code][/code] tags? :)

    Your code looks a little confuse to me also.. Please provide a runnable simplified test case so we can run it here and reproduce your issue. A good starting point to draw a sample code we can understand and run is by basing it on this sample: Gridpanel - Simple ArrayGrid.

    Instead of file loading you can just use a simpler set of static/hardcoded data like in that example.
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Hi, @fabricio.murta !

    These codes I'm using now can work.As you can see, I put the 'LoadGrid();' inside the 'Page_Load()', because if I just put it inside 'storeInfo_SubmitData()' but delete the 'Page_Load(null, null);' inside the gridpanel will not reload.

    To test, you need to add a key into web.config. (<add key="Alarm_Path" value="D:/alarm.csv"/>, this path can be any other path you want)
    And the file format is like this
    Click image for larger version. 

Name:	QQ图片20161229141801.png 
Views:	26 
Size:	10.0 KB 
ID:	24804
    Just make sure it contains five columns each row, what string inside doesn's matter.

    aspx code
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="InfoConfiguration.aspx.cs" Inherits="InfoConfiguration" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title>信息配置</title>
        <script>
            function insertRecord(grid) {
                var store = grid.store,
                    row = store.indexOf(store.insert(0, { SerialNum: 0 })[0]);
    
                Ext.defer(function () {
                    grid.editingPlugin.startEditByPosition({ row: row, column: 1 });
                }, 100);
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <ext:ResourceManager runat="server" />
        <ext:GridPanel runat="server" ID="Info_Grid" ColumnLines="true" Height="600" >
            <Store>
                <ext:Store runat="server" ID="storeInfo" OnSubmitData="storeInfo_SubmitData">
                    <Model>
                        <ext:Model ID="UserInfoModel" runat="server" IDProperty="ID">
                            <Fields>
                                <ext:ModelField Name="SerialNum" Type="Int"></ext:ModelField>
                                <ext:ModelField Name="Phone" Type="String"></ext:ModelField>
                                <ext:ModelField Name="Status" Type="String"></ext:ModelField>
                                <ext:ModelField Name="Judge" Type="String"></ext:ModelField>
                                <ext:ModelField Name="Value" Type="String"></ext:ModelField> 
                                <ext:ModelField Name="Type" Type="String"></ext:ModelField> 
                            </Fields>
                        </ext:Model>
                    </Model>
                </ext:Store>
            </Store>
            <SelectionModel>
                <ext:RowSelectionModel runat="server" Mode="Multi"></ext:RowSelectionModel>
            </SelectionModel>
            <ColumnModel>
                <Columns>
                    <ext:Column runat="server" ID="columnSerialNum" Width="70" Text="序号" DataIndex="SerialNum">
                        <Editor>
                            <ext:TextField runat="server" Editable="false"></ext:TextField>
                        </Editor>
                    </ext:Column>
                    <ext:Column runat="server" ID="columnPhone" Width="300" Text="电话号ç*" DataIndex="Phone">
                        <Editor>
                            <ext:TextField runat="server"></ext:TextField>
                        </Editor>
                    </ext:Column>
                    <ext:Column runat="server" ID="columnStatus" Width="250" Text="问题描述" DataIndex="Status">
                        <Editor>
                            <ext:TextField runat="server"></ext:TextField>
                        </Editor>
                    </ext:Column>
                    <ext:Column runat="server" ID="columnJudge" Width="250" Text="测点判æ–*" DataIndex="Judge">
                        <Editor>
                            <ext:TextField runat="server"></ext:TextField>
                        </Editor>
                    </ext:Column>
                    <ext:Column runat="server" ID="columnSecond" Width="150" Text="秒数/超限值" DataIndex="Value">
                        <Editor>
                            <ext:TextField runat="server"></ext:TextField>
                        </Editor>
                    </ext:Column>
                    <ext:Column runat="server" ID="column1" Width="150" Text="类型" DataIndex="Type">
                        <Editor>
                            <ext:TextField runat="server"></ext:TextField>
                        </Editor>
                    </ext:Column>
                </Columns>
            </ColumnModel>
            <BottomBar>
                <ext:Toolbar ID="Toolbar5" runat="server">
                    <Items>
                        <ext:ToolbarFill MaxWidth="330" runat="server" />
                        <ext:Button ID="AddRow" runat="server" Text="æ·»åŠ*è¡Œ" Width="100" Icon="Add">
                            <Listeners>
                                <Click Handler="insertRecord(#{Info_Grid});" />
                            </Listeners>
                        </ext:Button>
                        <ext:Button ID="DeleteRow" runat="server" Text="åˆ*除行" Width="100" Icon="Delete">
                            <Listeners>
                                <Click Handler="#{Info_Grid}.deleteSelected();" />
                            </Listeners>
                        </ext:Button>
                        <ext:Button ID="Save" runat="server" Text="保å*˜" Width="100" Icon="Disk">
                            <Listeners>
                                <Click Handler="#{Info_Grid}.submitData();" AutoPostBack="true" />
                            </Listeners>
                        </ext:Button>
                        <ext:ToolbarFill runat="server" />
                    </Items>
                </ext:Toolbar>
            </BottomBar>
            <Plugins>
                <ext:CellEditing runat="server" />
                <%--ext:RowEditing runat="server" ClicksToEdit="1"></--%>
            </Plugins>
        </ext:GridPanel>
        </div>
        </form>
    </body>
    </html>
    cs code
    using System;
    using System.IO;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Ext.Net;
    
    public partial class InfoConfiguration : System.Web.UI.Page
    {
        protected static string ALARM_PATH = System.Configuration.ConfigurationManager.AppSettings["Alarm_Path"].ToString();
        protected static List<object> DataSrc;
        protected static List<InfoUnit> DstData;
        protected static string[] head = { "电话号ç*", "问题描述", "测点判æ–*", "秒数/超限值", "类型" };
        protected static string[] datas = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (!IsPostBack)
            //{
            //    InputData();
            //    LoadGrid();
            //}
            InputData();
            LoadGrid();
        }
    
        protected void LoadGrid()
        {
            Info_Grid.GetStore().DataSource = DataSrc;
            Info_Grid.SetWidth("100%");
        }
        protected void LoadGrid(List<InfoUnit> DstData)
        {
            DataSrc = DstData.OfType<object>().ToList();
            Info_Grid.GetStore().DataSource = DataSrc;
            Info_Grid.SetWidth("100%");
        }
    
        protected void InputData()
        {
            try
            {
                if (File.Exists(ALARM_PATH))
                {
                    datas = File.ReadAllLines(ALARM_PATH, System.Text.Encoding.Default);
                    if (datas == null) return;
                    DataSrc = new List<object>();
                    for (int i = 1; i < datas.Length; i++)
                    {
                        string[] data = datas[i].Split(new char[] { ',', ',' });
                        if (data.Length != 5) continue;
                        DataSrc.Add(new InfoUnit() { SerialNum = i, Phone = data[0], Status = data[1], Judge = data[2], Value = data[3], Type = data[4] });
                    }
                }
            }
            catch (Exception ex)
            {
    
            }
        }
    
        protected void OutputData()
        {
            try
            {
                if (DataSrc == null) return;
                StreamWriter sw = new StreamWriter(ALARM_PATH, false, System.Text.Encoding.Default);
                sw.WriteLine(head[0] + "," + head[1] + "," + head[2] + "," + head[3] + "," + head[4]);
                foreach (InfoUnit info in DstData)
                {
                    sw.WriteLine(string.Format("{0}, {1}, {2}, {3}, {4}", info.Phone, info.Status, info.Judge, info.Value, info.Type));
                }
                sw.Close();
            }
            catch (Exception ex)
            {
            }
        }
        
        protected void storeInfo_SubmitData(object sender, StoreSubmitDataEventArgs e)
        {
            DstData = e.Object<InfoUnit>();
            OutputData();
            //LoadGrid(DstData);
            //Info_Grid.Reload();
            Page_Load(null, null);
        }
    }
    Last edited by eko; Dec 29, 2016 at 5:22 AM.
  4. #4
    Hello!

    Please, provide the class definition for InfoUnit.

    Why do we need the CSS file to reproduce the issue? Can't it be just replaced by a multi-line string like, maybe the below?

    datas = @"phone, status, jusdge, value, type
    13750029337, statusOne, 001;002, 500000, typeOne
    phoneTwo, statusTwo, 002;003, 500002, typeTwo
    phoneThree, statusThree, 003;004, 500003, typeThree";
    Fabrício Murta
    Developer & Support Expert
  5. #5
    Hello again, it seems that basically what you want to accomplish is submit your grid back to the server so you can save it, right?..

    I am pretty confident this example in examples explorer gives you a good simple way to do so:
    - Grid Panel - Selection Models - Submitting values

    It shows a reasonably elaborate submission of just the selected values. Instead you can just simplify it even more to submit the whole grid. There are several other grid saving/submitting alternative examples. You can find them just by searching either for 'submit' or 'save' or 'saving' in the examples explorer search input, to the upper left corner of the examples explorer interface.

    Hope these directions help you make your page work!
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. [CLOSED] Mask doesn't show on GridPanel store refresh
    By vadym.f in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Jul 12, 2013, 3:44 PM
  2. Replies: 1
    Last Post: Jun 12, 2012, 10:34 AM
  3. Replies: 5
    Last Post: Feb 01, 2012, 11:54 AM
  4. Replies: 2
    Last Post: Jan 16, 2012, 10:34 AM
  5. Replies: 1
    Last Post: Nov 25, 2009, 9:09 AM

Posting Permissions