[CLOSED] Databind nested lists to gridpanel

  1. #1

    [CLOSED] Databind nested lists to gridpanel

    I am having some trouble binding some data to a dynamic gridpanel. The problem is that I have a list of records that contains another list. I want the outside list to be the rows of my table, while the values from the inside list are the columns. Do you have any suggestions on how to do this?

    For example:
    I have a list of trailers, and each has a list of stops.
    I want the trailers to be the rows, and the names of each stop to be the columns, for instance:
    TrailerName Stop1 Stop2 Stop3
    Trailer1 T1S1 T1S2 T1S3
    Trailer2 T2S1 T2S2 T2S3
    Trailer3 T3S1 T3S2 T3S3

    Any ideas you have would be appreciated. Thank you.
    Last edited by Daniil; Mar 04, 2013 at 12:46 PM. Reason: [CLOSED]
  2. #2
    Please demonstrate that data (how it is configured)
    What exacly problems do you have? You can read list of stops and add fields and columns are based on that list
  3. #3
    Quote Originally Posted by Vladimir View Post
    Please demonstrate that data (how it is configured)
    What exacly problems do you have? You can read list of stops and add fields and columns are based on that list
    I am not sure how to bind the stops to the gridpanel. I can loop through the stops and add the appropriate number of columns, but I am not sure how to bind them afterwards. Ideally, I would like show the names of the stop as the column headers, and the arrivaltime of the each trailer at each of the stops (the stops would be the same for each trailer, but the times would be different).

    public class Trailer
    {
        public List<Stop> Stops = new List<Stop>();
        public string Name { get; set; }
    }
    
    public class Stop
    {
        public string Name { get; set; }
        public DateTime ArrivalTime { get; set; }
    }
  4. #4
    Something like this
    <%@ Page Language="C#" %> 
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
     
    <script runat="server">
        public class Trailer
        {
            public List<Stop> Stops = new List<Stop>();
            public string Name { get; set; }
        }
    
    
        public class Stop
        {
            public string Name { get; set; }
            public DateTime ArrivalTime { get; set; }
        }
        
        protected void Page_Load(object sender, EventArgs e)
        {
            List<Trailer> trailers = new List<Trailer>
            { 
                new Trailer{Name = "Trailer1", Stops = {
                    new Stop{Name = "T1S1"},
                    new Stop{Name = "T1S2"},
                    new Stop{Name = "T1S3"}
                }},
                
                new Trailer{Name = "Trailer2", Stops = {
                    new Stop{Name = "T2S1"},
                    new Stop{Name = "T2S2"},
                    new Stop{Name = "T2S3"}
                }},
                
                new Trailer{Name = "Trailer3", Stops = {
                    new Stop{Name = "T3S1"},
                    new Stop{Name = "T3S2"},
                    new Stop{Name = "T3S3"}
                }}
            };
    
    
            Model model = new Model();
            Store store = new Store
            {
                Model = 
                {                 
                    model
                }
            };
    
    
            GridPanel grid = new GridPanel
            {
                Store = { store },
                Width = 300,
                Height = 150
            };
    
    
            List<object> data = new List<object>();
            foreach (Trailer tr in trailers)
            {
                Dictionary<string, string> item = new Dictionary<string, string>();
                item.Add("Trailer", tr.Name);
                int i = 0;
                foreach (Stop stop in tr.Stops)
                {
                    item.Add("Stop" + ++i, stop.Name);
                }
    
    
                foreach (string key in item.Keys)
                {
                    if (model.Fields.Get(key) == null)
                    {
                        model.Fields.Add(key);
                        grid.ColumnModel.Columns.Add(new Column { DataIndex = key, Text = key, Flex = 1 });
                    }
                }
                
                data.Add(item);
            }
    
    
            store.Data = data;
    
    
            this.Form.Controls.Add(grid);
        }
    </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></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server"/>
       
        </form>
    </body>
    </html>
  5. #5
    Thank you, that works great!

    Do you have a suggestion on how I can save the data? I.e. I want a save button at the bottom that will call a server-side method with the name-value pairs from each row. I am using a ComponentColumn to allow them to edit the records.
  6. #6
    You can deserialize data to 'Dictionary<string, string>' like in the following sample
    https://examples2.ext.net/#/GridPane...s/Save_Filter/

    After that transform dictionary to any required business logic object

Similar Threads

  1. GridPanel Databind Not Working
    By tozza_d in forum 1.x Help
    Replies: 1
    Last Post: Aug 01, 2012, 10:58 AM
  2. [CLOSED] Nested data in nested grids
    By FAS in forum 1.x Legacy Premium Help
    Replies: 16
    Last Post: Apr 19, 2012, 7:51 PM
  3. [CLOSED] GridPanel.DataBind in TaskManager
    By srsantos in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Jun 30, 2011, 8:48 AM
  4. ComboBox in GridPanel databind issue
    By HexElffilter in forum 1.x Help
    Replies: 0
    Last Post: Jan 31, 2011, 2:08 PM
  5. Bullets and numbered lists in HtmlEditor
    By jsemple in forum 1.x Help
    Replies: 0
    Last Post: Mar 04, 2009, 4:21 PM

Tags for this Thread

Posting Permissions