Only the last row from XML shows at GridPanel

  1. #1

    Only the last row from XML shows at GridPanel

    Hi,
    I have a grid panel
    All the data is from XML file.
    I've convert the XML to List<Plants>

    This is the Model:

    List<Plants> plantsFromXML = new List<Plants>();
    plantsFromXML = XMLReader.RetrunListOfPlants();
    return XMLReader.RetrunListOfPlants();   -------> This shows only the last item in the list
    
    List<Plants> test = new List<Plants>
    {
       new Plants{id=1, common="Plant1", price=11122, indoor="true"},
       new Plants{id=2, common="Plant2", price=1, indoor="true"},
       new Plants{id=3, common="Plant3", price=12, indoor="true"},
       new Plants{id=4, common="Plant4", price=4, indoor="true"},
       new Plants{id=5, common="Plant5", price=111, indoor="true"},
       new Plants{id=6, common="Plant6", price=2211, indoor="true"}
    };
    
    return test;  -----------> This shows ALL the plants!
    This is the View:
    @{
        ViewBag.Title = "Index";
        Layout = "~/Views/Shared/_Layout.cshtml"; 
    }
    
    <h2>Index</h2>
    
    @model IEnumerable<TestMVC.Models.Plants>
    <h2>Product List using XML</h2>
    
    @section headtag
    {
        <script>
            var onWrite = function (store, operation) {
                var record = operation.getRecords()[0],
                    name = Ext.String.capitalize(operation.action),
                    verb;
    
                if (name == 'Destroy') {
                    verb = 'Destroyed';
                } else {
                    verb = name + 'd';
                }
    
                Ext.net.Notification.show({ title: name, html: Ext.String.format("{0} user: {1}<br/>{2}", verb, record.getId(), operation.getResultSet().message) });
            };
        </script>
    }
    
    
    @section gridPlants
    {
        <h1>Plants List</h1>
    
        @(Html.X().GridPanel()
                    .Icon(Icon.Table)
                    .Frame(true)
                    .Title("Plants")
                    .Height(400)
                    .Width(700)
                            .Store(
                                Html.X().StoreForModel().Control(s =>
                                {
                                    s.AutoSync = true;
                                    s.Proxy.Add(
                                        new RestProxy
                                        {
                                            AppendAction = false,
                                            Reader = {
                                        new JsonReader {
                                            RootProperty = "data",
                                            MessageProperty = "message"
                                        }
                                    },
                                            API =
                                            {
                                                Read = Url.Action("Read"),
                                                Update = Url.Action("Update"),
                                                Create = Url.Action("Create"),
                                                Destroy = Url.Action("Destroy")
                                            },
                                            Writer = {
                                        new JsonWriter
                                        {
                                            AllowSingle = true
                                        }
                                    }
                                        }
                                    );
                                    s.Listeners.Write.Fn = "onWrite";
                                    s.Listeners.Write.Delay = 1;
                                })
                            )
                    .ColumnModel(
                            Html.X().ColumnFor(Model, item => item.id)
                            .ToBuilder<Column.Builder>()
                            .Width(40)
                            .Renderer("return record.phantom ? '' : value;"),
    
                            Html.X().ColumnFor(Model, item => item.common)
                            .ToBuilder<Column.Builder>()
                            .Flex(1)
                            .Editor(
                                Html.X().TextField().AllowBlank(false)
                            ),
    
                            Html.X().ColumnFor(Model, item => item.light)
                            .ToBuilder<Column.Builder>()
                            .Flex(1)
                            .Editor(
                                Html.X().TextField().AllowBlank(false)
                            ),
    
                            Html.X().ColumnFor(Model, item => item.price)
                            .ToBuilder<Column.Builder>()
                            .Flex(1)
                            .Editor(
                                Html.X().TextField().AllowBlank(false)
                            ),
    
                            Html.X().ColumnFor(Model, item => item.availability)
                            .ToBuilder<Column.Builder>()
                            .Flex(1)
                            .Editor(
                                Html.X().TextField().AllowBlank(false)
                            ),
                            
                            Html.X().ColumnFor(Model, item => item.indoor)
                            .ToBuilder<Column.Builder>()
                            .Flex(1)
                            .Editor(
                                Html.X().TextField().AllowBlank(false)
                            )
                    )
                    .TopBar(
                        Html.X().Toolbar()
                            .Items(
                                Html.X().Button()
                                    .Text("Add")
                                    .Icon(Icon.Add)
                                    .Handler("this.up('grid').store.insert(0, new Plant());this.up('grid').editingPlugin.startEdit(0, 0);"),
    
                                Html.X().Button()
                                    .ItemID("btnRemove")
                                    .Text("Delete")
                                    .Icon(Icon.Exclamation)
                                    .Handler("this.up('grid').deleteSelected();")
                            )
                    )
                    .Plugins(
                        Html.X().RowEditing()
                            .Listeners(l =>
                            {
                                l.CancelEdit.Handler = "if(e.record.phantom){e.store.remove(e.record);}";
                            })
                    )
        )
    } 
    How can i show ALL the plants from the XML file?

    Thanks!
  2. #2

    Problem Solved!!

    The id was always the same (1)

    Thanks.

Similar Threads

  1. Gridpanel with datasource shows empty rows
    By darylpeeters in forum 2.x Help
    Replies: 2
    Last Post: May 31, 2012, 1:03 PM
  2. Replies: 1
    Last Post: Dec 12, 2011, 5:14 PM
  3. Replies: 2
    Last Post: Nov 30, 2010, 8:30 PM
  4. Replies: 2
    Last Post: May 19, 2010, 4:07 PM
  5. Replies: 2
    Last Post: Oct 25, 2008, 5:10 AM

Tags for this Thread

Posting Permissions