How to bind Gridpanel(store) with datatable from controller

  1. #1

    How to bind Gridpanel(store) with datatable from controller

    View
    ======
    <ext:GridPanel
                                                    ID="GridCustomer"
                                                    runat="server"
                                                    Title="Customer"
                                                    Width="1000"
                                                    Height="350">
                                                    <Store>
                                                        <ext:Store ID="Store2" runat="server">
                                                            <Model>
                                                                <ext:Model runat="server">
                                                                    <Fields>
                                                                        <ext:ModelField Name="PO" Type="String" />
                                                                        <ext:ModelField Name="PODATE" Type="Date" DateFormat="dd/MM/YYYY"  />
                                                                        <ext:ModelField Name="Amount" Type="Float" />
                                                                        <ext:ModelField Name="POID" Type="int"/>
                                                                    </Fields>
                                                                </ext:Model>
                                                            </Model>
                                                        </ext:Store>
                                                    </Store>
                                                    <ColumnModel>
                                                        <Columns>
                                                            <ext:RowNumbererColumn ID="RowNumbererColumn1" runat="server" />
                                                            <ext:Column runat="server" Text="PO" DataIndex="PO" Width="250" Sortable="false" />
                                                            <ext:Column runat="server" Text="PO Date" DataIndex="PODATE" Width="150"></ext:Column>
                                                            <ext:Column runat="server" Text="Amount" DataIndex="Amount" Width="150"></ext:Column>
                                                        </Columns>
                                                    </ColumnModel>
                                                </ext:GridPanel>
    Controller
    ========

    public void CreateTable()
            {
                DataTable TabCustomerPO = new DataTable();
                TabCustomerPO.Columns.Add("ID", typeof(string));
                TabCustomerPO.Columns.Add("PO", typeof(string));
                TabCustomerPO.Columns.Add("PODATE", typeof(DateTime));
                TabCustomerPO.Columns.Add("Amount", typeof(decimal));
                TabCustomerPO.Columns.Add("POID", typeof(int));
                Session["CUSTOMERPO"] = TabCustomerPO;
            }
    
    public ActionResult btnAdd_Click(string PODATE, string POREF, float POAMOUNT)
            {
                if (Session["CUSTOMERPO"] == null)
                {
                    CreateTable();
                }
    
                TabCustomerPO = Session["CUSTOMERPO"] as DataTable;
                drow = TabCustomerPO.NewRow();
                drow["ID"] = TabCustomerPO.Rows.Count + 1;
                drow["PO"] = POREF.Trim().ToString();
                string[] CustDate=PODATE.ToString().Split('T');
                drow["PODATE"] = Convert.ToDateTime(CustDate[0].ToString().Replace('"', ' ').Trim());  //string.Format("{0:MM/dd/yyyy}", DateTime.ParseExact(CustDate[0].ToString(), "dd/MM/yyyy", CultureInfo.InvariantCulture));
                drow["AmountSGD"] = Convert.ToDecimal(POAMOUNT.ToString());
                drow["POID"] = 0;
                TabCustomerPO.Rows.Add(drow);
                Session["CUSTOMERPO"] = TabCustomerPO;
                ViewData["CUSTOMERPO"] = TabCustomerPO;
                return this.Direct();
            }
    Please give me solution, how to bind data's from controller to view page (Grid panel - store2)

    Thanks
    Last edited by Daniil; Jul 03, 2014 at 8:27 AM. Reason: Please use [CODE] tags
  2. #2
    Hi @sunshineenterprises,

    Welcome to the Ext.NET forums!

    With a DirectResult you cannot pass a ViewData. As for Session, you won't be able to access it on client.

    This example demonstrates what you could do:
    http://mvc.ext.net/#/GridPanel_ArrayGrid/Remote_Load/

    Also you might need to use a ModelSerializer to serialize a DataTable.
    http://forums.ext.net/showthread.php?26842

Similar Threads

  1. [CLOSED] [MVC] Bind empty store in gridPanel
    By Tactem in forum 2.x Legacy Premium Help
    Replies: 11
    Last Post: Oct 04, 2014, 9:21 AM
  2. Replies: 3
    Last Post: Apr 11, 2012, 1:56 AM
  3. Replies: 1
    Last Post: Apr 09, 2012, 1:07 PM
  4. Bind Grito do Datatable
    By PoloTheMonk in forum 1.x Help
    Replies: 0
    Last Post: Nov 20, 2009, 1:20 PM
  5. Replies: 1
    Last Post: Jul 30, 2009, 10:32 AM

Posting Permissions