[CLOSED] GridPanel with Dynamic Fields and Columns

  1. #1

    [CLOSED] GridPanel with Dynamic Fields and Columns

    Hi

    I'm trying to develop a GridPanel where the number of model fields and grid columns varies according to the data settings. I've developed a simple example adding a model field and a column but I can't seem to make it work. I've seen examples based on Web Forms but I can't find any help for MVC.

    This is the View:

    <!DOCTYPE html>
    <html>
    <head>
        <title></title>
        <script>
    
        </script>
    </head>
    <body>
    @Html.X().ResourceManager().ScriptMode(Ext.Net.ScriptMode.Debug).SourceFormatting(true)
    @(Html.X().GridPanel().Width(352)
        .Title("Users").ID("GridPanel").Border(true)
        .Store(Html.X().Store()
            .ID("Store")
            .Model(Html.X().Model().ID("Model").IDProperty("ID")
                .Fields(
                    new ModelField("ID", ModelFieldType.Int)
                    )
                )
            .Proxy(Html.X().AjaxProxy().Url(Url.Action("Read")).Reader(Html.X().JsonReader().RootProperty("data"))))
        .ColumnModel(
    
        )
    )
    </body>
    </html>
    This is the Controller:

    using Ext.Net;
    using Ext.Net.MVC;
    using System;
    using System.Collections.Generic;
    using System.Web.Mvc;
    
    namespace ExtNetBugsMVC.Controllers
    {
        public class HomeController : Controller
        {
            public ActionResult Index()
            {
                return View();
            }
            public ActionResult Read()
            {
                List<User> lstUsers = new List<User>();
                lstUsers.Add(new User(1000, "Jeff"));
                lstUsers.Add(new User(1001, "James"));
                X.GetCmp<Model>("Model").Fields.Add(new ModelField("Name"));
                X.GetCmp<GridPanel>("GridPanel").ColumnModel.Columns.Add(new Column { DataIndex = "Name", Text = "Name" });
                X.GetCmp<GridPanel>("GridPanel").Reconfigure();
                return this.Store(lstUsers);
            }
        }
    
        public class User
        {
            public User()
            {
            }
            public User(int id, string name)
            {
                ID = id;
                Name = name;
            }
            public int ID { get; set; }
            public string Name { get; set; }
        }
    }
    Last edited by fabricio.murta; Dec 31, 2015 at 12:58 PM. Reason: [CLOSED]
  2. #2
    Hi @Argenta,

    X.GetCmp<> returns a proxy component. For example, a Model returned by X.GetCmp<> doesn't contain all the ModelFields that are defined on a View.

    I recommend this approach:
    https://examples3.ext.net/#/GridPane...g_with_handler
  3. #3
    Thanks Daniil

    In practice I don't think this approach will suit my need which is a bit more complicated than my example. However, I am interested in getting this example to work because it could well be useful in other applications. I've got so far but I'm stuck on getting it to work in MVC mode, specifically how to return the metadata.

    This is my revised View:

    <!DOCTYPE html>
    <html>
    <head>
        <title></title>
        <script>
    
        </script>
    </head>
    <body>
    @Html.X().ResourceManager().ScriptMode(Ext.Net.ScriptMode.Debug).SourceFormatting(true)
    @(Html.X().GridPanel().Width(352)
        .Title("Users").ID("GridPanel").Border(true)
        .Store(Html.X().Store()
            .ID("Store")
            .Model(Html.X().Model().ID("Model").IDProperty("ID")
                .Fields(
                    new ModelField("ID", ModelFieldType.Int)
                    )
                )
            .Proxy(Html.X().AjaxProxy().Url(Url.Action("Read")).Reader(Html.X().JsonReader().RootProperty("data")))
                .Listeners(lst => { lst.MetaChange.Handler = "#{GridPanel}.reconfigure(null, meta.columns)"; })
            )
            
        .ColumnModel(
    
        )
    )
    </body>
    </html>
    And this is my revised Controller:

    using Ext.Net;
    using Ext.Net.MVC;
    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.Mvc;
    
    namespace ExtNetBugsMVC.Controllers
    {
        public class HomeController : Controller
        {
            public ActionResult Index()
            {
                return View();
            }
            public ActionResult Read()
            {
                object data = new List<object>{new {ID = 1000, StringField = "Jeff"}, new {ID = 1000, StringField = "Jeff"}};
                MetaConfig metaData = MetaConfig.From(data);
                metaData.IDProperty = "ID";
                metaData.RootProperty = "data";
    
                return this.Store(JSON.Serialize(data));
            }
        }
    }
    As I mentioned I can't work out how to return the metadata.

    Thanks for your help

    Jeff
  4. #4
    Please use:
    public ActionResult Read()
    {
        object data = new List<object> { new { ID = 1000, StringField = "Jeff" }, new { ID = 1000, StringField = "Jeff" } };
        MetaConfig metaData = MetaConfig.From(data);
        metaData.IDProperty = "ID";
        metaData.RootProperty = "data";
    
        StoreResponseData response = new StoreResponseData
        {
            MetaData = metaData,
            Data = JSON.Serialize(data)
        };
    
        return this.Content(response.ToString());
    }
    I think this.Store() and StoreResult really miss overloads and parameters to deal with MetaData. Created an Issue:
    https://github.com/extnet/Ext.NET/issues/1158
  5. #5
    Thanks Daniil

    It's certainly not intuitive!

    Jeff
  6. #6
    Yeah, agree.

    Please clarify does that help to resolve the original requirement?
  7. #7
    Hello Jeff and Daniil!

    When we fix the github issue, we'll post a feedback here. Assuming this helped with the matter for now and closing the thread. Please let us know otherwise.
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. Replies: 0
    Last Post: Oct 15, 2012, 12:38 PM
  2. [CLOSED] Dynamic Columns and Fields MVC application.
    By romeu in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Feb 27, 2012, 6:23 PM
  3. [CLOSED] Dynamic Columns and Fields MVC application
    By romeu in forum 2.x Legacy Premium Help
    Replies: 10
    Last Post: Feb 27, 2012, 6:08 PM
  4. Replies: 2
    Last Post: Feb 09, 2010, 6:51 PM
  5. [CLOSED] GridPanel Dynamic Editor Fields
    By ljcorreia in forum 1.x Legacy Premium Help
    Replies: 11
    Last Post: Jan 18, 2010, 2:13 PM

Posting Permissions