[CLOSED] ComponentColumn editor does not save values

  1. #1

    [CLOSED] ComponentColumn editor does not save values

    Hi,
    I am trying to use example "https://examples2.ext.net/#/GridPanel/ComponentColumn/Editor/" to create a dynamyc list of controls inside a form.

    I set a List as a datasource for the gridpanel.

    My problem occurs when I add a new row after editing a row: all previous values are cleared.

    I thought component column automatically commits and save values to the list.

    How can I persist values set in the rows cells?

    Thanks in advance
    M


    
    
        public partial class Ticket_Details : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
                if (!X.IsAjaxRequest)
                {
                    // on load I create the first row, it works 
                    dataSource = new List<Intervento>();
                    Intervento intervento = new Intervento();
    
                    dataSource.Add(intervento);
    
                    this.stRigaListino.DataSource = DataSource;
    
                    this.stRigaListino.DataBind();
                }
    
            }
    
            protected void btnAddService_Click(object sender, DirectEventArgs e)
            {
    
                // First I save values in existing rows
                this.stRigaListino.CommitChanges();
    
                // Then I put a new record in the list
                Intervento intervento = new Intervento();
                dataSource.Add(intervento);
    
                // Then databind the grid but old values are cleared!!
                this.stRigaListino.DataSource = DataSource;
    
                this.stRigaListino.DataBind();
            }
    
            private static List<Intervento> dataSource;
    
            public static List<Intervento> DataSource
            {
                get
                {
                    return dataSource;
                }
            }
    
    
        }
    
        public class Intervento
        {
            public string ID
            {
                get;
                set;
            }
            public string Descrizione
            {
                get;
                set;
            }
            public string MarcaId
            {
                get;
                set;
            }
            public string Modello
            {
                get;
                set;
            }
            public bool RAEE
            {
                get;
                set;
            }
            public bool Trasporto
            {
                get;
                set;
            }
            public bool DisponibilitaMerce
            {
                get;
                set;
            }
            public DateTime? DataDisponibilitaMerce
            {
                get;
                set;
            }
            public bool MagazzinoRitiro
            {
                get;
                set;
            }
        }
    Last edited by Daniil; Jan 18, 2013 at 9:25 AM. Reason: [CLOSED]
  2. #2
    Hello!

    Can you provide full and simplified sample (with markup) to reproduce your problem?

    http://forums.ext.net/showthread.php...ation-Required
  3. #3
    Hi,
    here is the running example.

    Steps to reproduce:
    1) edit a value
    2) click "add Row" button

    Error: editings at step 1 are lost.

    Thanks in advance.
    Marco Morreale


    
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
    
           public static List<object> myList;
    
           protected void Page_Load(object sender, EventArgs e)
            {
    
                if (!X.IsAjaxRequest)
                {
                    myList = new List<object>();
    
                    for (int i = 1; i < 10; i++)
                    {
                        myList.Add(new object[] { i, i, "Text " +  i, DateTime.Now.Date });
                    }
    
                    this.Store1.DataSource = myList;
    
                    this.Store1.DataBind();
                }
            }
    
            protected void btnAddService_Click(object sender, DirectEventArgs e)
            {
                this.Store1.CommitChanges();
    
                Intervento intervento = new Intervento();
                myList.Add(new object[] { 11, 11, "Text 11", DateTime.Now.Date });
    
                this.Store1.DataSource = myList;
    
                this.Store1.DataBind();
            }
    
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>ComponentColumn Editor - Ext.NET Examples</title>
        <link href="/resources/css/examples.css" rel="stylesheet" />    
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            
            <h1>ComponentColumn as Editor</h1>
    
            <ext:GridPanel 
                runat="server" 
                Title="ComponentColumn Editor" 
                Width="600" 
                Height="300">
                <Store>
                    <ext:Store ID="Store1" runat="server">
                        <Model>
                            <ext:Model runat="server">
                                <Fields>
                                    <ext:ModelField Name="IntField" Type="Int" />
                                    <ext:ModelField Name="ComboField" Type="Int" />
                                    <ext:ModelField Name="TextField" Type="String" />
                                    <ext:ModelField Name="DateField" Type="Date" />
                                </Fields>
                            </ext:Model>
                        </Model>
                    </ext:Store>
                </Store>
                <ColumnModel runat="server">
                    <Columns>
                        <ext:ComponentColumn 
                            runat="server" 
                            Editor="true"
                            DataIndex="IntField"
                            Flex="1"
                            Text="Integer">
                            <Component>
                                <ext:NumberField runat="server" />
                            </Component>
                        </ext:ComponentColumn>
    
                        <ext:ComponentColumn 
                            runat="server" 
                            Editor="true"
                            DataIndex="ComboField"
                            Flex="1"
                            Text="ComboBox">
                            <Component>
                                <ext:ComboBox runat="server">
                                    <Items>
                                        <ext:ListItem Text="Item 1" Value="1" Mode="Raw" />
                                        <ext:ListItem Text="Item 2" Value="2" Mode="Raw" />
                                        <ext:ListItem Text="Item 3" Value="3" Mode="Raw" />
                                        <ext:ListItem Text="Item 4" Value="4" Mode="Raw" />
                                        <ext:ListItem Text="Item 5" Value="5" Mode="Raw" />
                                        <ext:ListItem Text="Item 6" Value="6" Mode="Raw" />
                                        <ext:ListItem Text="Item 7" Value="7" Mode="Raw" />
                                        <ext:ListItem Text="Item 8" Value="8" Mode="Raw" />
                                        <ext:ListItem Text="Item 9" Value="9" Mode="Raw" />
                                    </Items>
                                </ext:ComboBox>
                            </Component>
                        </ext:ComponentColumn>
    
                        <ext:ComponentColumn 
                            runat="server" 
                            Editor="true"
                            DataIndex="TextField"
                            Flex="1"
                            Text="Text">
                            <Component>
                                <ext:TextField runat="server" />
                            </Component>
                        </ext:ComponentColumn>
    
                        <ext:ComponentColumn 
                            runat="server" 
                            Editor="true"
                            DataIndex="DateField"
                            Flex="1"
                            Text="Date">
                            <Component>
                                <ext:DateField runat="server" />
                            </Component>
                        </ext:ComponentColumn>
                    </Columns>
                </ColumnModel>          
            <Buttons><ext:Button 
                runat="server" 
                Text="Add Row" 
                Icon="Add" 
                OnDirectClick="btnAddService_Click" 
                />
            </Buttons>
            </ext:GridPanel>  
        </form>
    </body>
    </html>
  4. #4
    Thank you for the sample.

    Well, you rebind the old data with the myList.

    The following is enough to add a new row.

    Example
    protected void btnAddService_Click(object sender, DirectEventArgs e)
    {
        this.Store1.Add(new List<object>() { new object[] { 11, 11, "Text 11", DateTime.Now.Date } });
    
        // or
        // this.Store1.Add(new { IntField = 11, ... });
    }
  5. #5
    Thank you Daniil,
    but this way myList is never modified so I can't process the rows later.

    I also have a Save button (server side); on click I want to loop through myList items to process data in the gridpanel (save to db).

    How can I achive this?

    I tried "this.Store1.Data" or "this.Store1.record" but theese are null.

    Thanks in advance.
    Marco
  6. #6
    Well, you can add a record to the list after the Store's Add call.

    But do you really need this list?

    How will you manage editing? Are you going to monitor client side editing and update that list, on interim level between the client data and the database?

    Personally, I would use the native grid/store data saving mechanism as demonstrated in our examples.
    https://examples2.ext.net/#/search/saving
    https://examples2.ext.net/#/GridPanel/Update/AutoSave/
    https://examples2.ext.net/#/GridPanel/Update/Batch/
    https://examples2.ext.net/#/GridPane...SqlDataSource/
  7. #7
    Thank you, Daniil

    This fitted perfectly: https://examples2.ext.net/#/GridPanel/Update/Batch/

    M

Similar Threads

  1. Replies: 13
    Last Post: Dec 05, 2012, 6:55 AM
  2. [CLOSED] How to use DirectEvents in ComponentColumn as Over Editor
    By UnifyEducation in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Nov 30, 2012, 1:00 PM
  3. [CLOSED] Razor - ComponentColumn as Over Editor
    By MTSI in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Nov 23, 2012, 11:37 AM
  4. ComponentColumn Editor Bug?
    By Doug.Morrow in forum 2.x Help
    Replies: 6
    Last Post: Aug 08, 2012, 7:30 PM
  5. Replies: 3
    Last Post: Apr 20, 2010, 5:24 PM

Posting Permissions