[CLOSED] Dynamic Columns and Fields MVC application.

  1. #1

    [CLOSED] Dynamic Columns and Fields MVC application.

    I need create dynamic Collumns in GridPanel and Fields in Store.

    My application is MVC.

    Can you send me one example for this, please ?


    Thank's
    Last edited by Daniil; Feb 29, 2012 at 4:53 PM. Reason: [CLOSED]
  2. #2
    Hi,

    Here you are.

    Example View
    <%@ Page Language="C#" %>
      
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
     
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store store = this.GridPanel1.GetStore();
                store.DataSource = new object[] 
                { 
                    new 
                    { 
                        test = "test1" 
                    },
                    new 
                    { 
                        test = "test2" 
                    }
                };
                store.DataBind();
            }
        }
    </script>
     
    <!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 runat="server">
        <title>Ext.Net.MVC Example</title>
     
        <script type="text/javascript">
            var onSuccess = function (grid, result) {
                var store = grid.getStore();
     
                grid.addColumn(Ext.decode(result.column));
                
                store.addField(Ext.decode(result.field), -1, true);
     
                //test
                store.loadData([{
                    test : "test1",
                    someDataIndex : "new1"
                }, {
                    test : "test2",
                    someDataIndex : "new2"
                }]);
            };
        </script>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
        <ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true">
            <Store>
                <ext:Store runat="server">
                    <Reader>
                        <ext:JsonReader runat="server">
                            <Fields>
                                <ext:RecordField Name="test" />
                            </Fields>
                        </ext:JsonReader>
                    </Reader>
                </ext:Store>
            </Store>
            <ColumnModel runat="server">
                <Columns>
                    <ext:Column Header="Test" DataIndex="test" />
                </Columns>
            </ColumnModel>
        </ext:GridPanel>
        <ext:Button runat="server" Text="Add column">
            <DirectEvents>
                <Click 
                    Url="/Test/AddColumn" 
                    Success="onSuccess(#{GridPanel1}, result.result);" />
            </DirectEvents>
        </ext:Button>
    </body>
    </html>
    Example Controller Action
    public ActionResult AddColumn()
    {
        
        Column c = new Column()
        {
            Header = "New",
            DataIndex = "someDataIndex"
        };
    
        RecordField rf = new RecordField()
        {
            Name = "someDataIndex"
        };
    
        AjaxResult r = new AjaxResult();
        r.Result = new
        {
            column = c.Serialize(),
            field = new ClientConfig().Serialize(rf)
        };
    
        return r;
    }
    See the following post for this solution using Ext.NET v2,
    http://forums.ext.net/showthread.php...ll=1#post75369

Similar Threads

  1. [CLOSED] number fields in grid/columns
    By marco.morreale in forum 2.x Legacy Premium Help
    Replies: 6
    Last Post: May 18, 2012, 6:22 PM
  2. [CLOSED] Dynamic Columns and Fields MVC application
    By romeu in forum 2.x Legacy Premium Help
    Replies: 10
    Last Post: Feb 27, 2012, 7:08 PM
  3. Replies: 2
    Last Post: Feb 09, 2010, 7:51 PM
  4. Dynamic fields
    By Wtower in forum 1.x Help
    Replies: 2
    Last Post: Apr 20, 2009, 6:57 PM
  5. [CLOSED] Clear store fields and grid columns from AjaxEvent
    By jchau in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Feb 22, 2009, 3:18 PM

Posting Permissions