[CLOSED] Gridpanel - RowEditor - Autosave

  1. #1

    [CLOSED] Gridpanel - RowEditor - Autosave

    Is there a way to save the changes to a gridpanel row after edit without using a save button? So instead, have the values change in the grid/store and save them all at one time with the rest of the page? I didn't see any way to turn off the row by row saving, but need to save an entire page at once.

    What I am looking for is the following:

    * Click a row to turn it to edit mode
    * Make changes to the columns in row and click out of the row - changes are applied to the row but not saved to database
    * When the entire page is saved, all the grid row changes are also saved.
    Last edited by Daniil; Mar 07, 2011 at 9:20 PM. Reason: [CLOSED]
  2. #2
    Hi,

    I don't understand why you use AutoSave="true" if you need to save the changes only 'when the entire page is saved'.

    To save manually please use GridPanel's or Store's .save() method.
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi,

    I don't understand why you use AutoSave="true" if you need to save the changes only 'when the entire page is saved'.

    To save manually please use GridPanel's or Store's .save() method.
    I am not using AutoSave yet, just was trying to set up the grid to allow row by row editing but to not do the saves on each row changed. Instead the changes would be saved just locally and all submitted at once when the rest of the page is. So I guess the orginal question was - how to remove the buttons on each row but still allow each row to be clicked to edit the values. Then when you click the next row or tab out of the edited row it is "saved" just locally and ready to be submitted when the entire page's save button is pressed.
  4. #4
    Hi,

    I've prepared the sample basing on
    https://examples1.ext.net/#/GridPane...ins/RowEditor/

    Example
    <%@ Page Language="C#" %>
    
    <%@ Import Namespace="System.Collections.ObjectModel" %>
    <%@ Import Namespace="System.Collections.Generic" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                var store = this.GridPanel1.GetStore();
                
                store.DataSource = new List<object>
                {
                    new { 
                        Name = "Bill Foot", 
                        Email = "bill.foot@object.net", 
                        Start = new DateTime(2007, 2, 5), 
                        Salary = 37000, 
                        Active = true
                    },
                    new { 
                        Name = "Bill Little", 
                        Email = "bill.little@object.net", 
                        Start = new DateTime(2009, 6, 13), 
                        Salary = 53000, 
                        Active = true
                    },
                    new { 
                        Name = "Bob Jones", 
                        Email = "bob.jones@object.net", 
                        Start = new DateTime(2008, 10, 6), 
                        Salary = 70000, 
                        Active = true
                    },
                    new { 
                        Name = "Bob Train", 
                        Email = "bob.train@object.net", 
                        Start = new DateTime(2009, 5, 5), 
                        Salary = 68000, 
                        Active = true
                    },
                    new { 
                        Name = "Chris Johnson", 
                        Email = "chris.johnson@object.net", 
                        Start = new DateTime(2009, 1, 25), 
                        Salary = 47000, 
                        Active = true
                    }
                };
                
                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>GridPanel with RowEditor Plugin - Ext.NET Examples</title>
        
        <ext:XScript runat="server">
            <script type="text/javascript">
                var addEmployee = function () {
                    var grid = #{GridPanel1};
                    grid.getRowEditor().stopEditing();
                    
                    grid.insertRecord(0, {
                        name   : "New Guy",
                        email  : "guy@object.net",
                        start  : (new Date()).clearTime(),
                        salary : 50000,
                        active : true
                    });
                    
                    grid.getView().refresh();
                    grid.getSelectionModel().selectRow(0);
                    grid.getRowEditor().startEditing(0);
                }
                
                var removeEmployee = function () {
                    var grid = #{GridPanel1};
                    grid.getRowEditor().stopEditing();
                    
                    var s = grid.getSelectionModel().getSelections();
                    
                    for (var i = 0, r; r = s[i]; i++) {
                        #{Store1}.remove(r);
                    }
                }
            </script>
        </ext:XScript>
        
        <script type="text/javascript">
            var onClick = function (e) {
                if (RowEditor1.editing 
                    && !GridPanel1.getView().mainBody.contains(e.target)
                    && !RowEditor1.bwrap.contains(e.target)) {
                    
                    RowEditor1.stopEditing(true);
                }
            }
            
            var onAfterRender = function () {
                RowEditor1.startEditing = RowEditor1.startEditing.createInterceptor(startEditingInterceptor);
            }
            
            var startEditingInterceptor = function () {
                this.hasFocus = true;
                this.stopEditing(true);
            }
        </script>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server">
                <Listeners>
                    <DocumentReady Handler="Ext.getBody().on('click', onClick, this, { delay : 100});" />
                </Listeners>
            </ext:ResourceManager>
            
            <h1>GridPanel with RowEditor Plugin</h1>
            
            <ext:GridPanel 
                ID="GridPanel1" 
                runat="server"
                Width="600"
                Height="400"
                AutoExpandColumn="name"
                Title="Employees">
                <Store>
                    <ext:Store ID="Store1" runat="server">
                        <Reader>
                            <ext:JsonReader>
                                <Fields>
                                    <ext:RecordField Name="name" Mapping="Name" Type="String" />
                                    <ext:RecordField Name="email" Mapping="Email" Type="String" />
                                    <ext:RecordField Name="start" Mapping="Start" Type="Date" />
                                    <ext:RecordField Name="salary" Mapping="Salary" Type="Float" />
                                    <ext:RecordField Name="active" Mapping="Active" Type="Boolean" />
                                </Fields>
                            </ext:JsonReader>
                        </Reader>
                    </ext:Store>
                </Store>
                <Plugins>
                    <ext:RowEditor ID="RowEditor1" runat="server" />
                </Plugins>
                <View>
                    <ext:GridView runat="server" MarkDirty="false" />
                </View>
                <TopBar>
                    <ext:Toolbar runat="server">
                        <Items>
                            <ext:Button runat="server" Text="Add Employee" Icon="UserAdd">
                                <Listeners>
                                    <Click Fn="addEmployee" />
                                </Listeners>
                            </ext:Button>
                            <ext:Button runat="server" Text="Remove Employee" Icon="UserDelete">
                                <Listeners>
                                    <Click Fn="removeEmployee" />
                                </Listeners>
                            </ext:Button>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <SelectionModel>
                    <ext:RowSelectionModel runat="server" />
                </SelectionModel>
                <ColumnModel>
                    <Columns>
                        <ext:RowNumbererColumn />
                        <ext:Column 
                            ColumnID="name" 
                            Header="First Name" 
                            DataIndex="name" 
                            Width="220" 
                            Sortable="true">
                            <Editor>
                                <ext:TextField runat="server" AllowBlank="false" />
                            </Editor>
                        </ext:Column>
                        <ext:Column Header="Email" DataIndex="email" Width="150">
                            <Editor>
                                <ext:TextField runat="server" AllowBlank="false" Vtype="email" />
                            </Editor>
                        </ext:Column>
                        <ext:DateColumn 
                            Header="Start Date" 
                            DataIndex="start" 
                            Format="MM/dd/yyyy" 
                            Width="100" 
                            Sortable="true">
                            <Editor>
                                <ext:DateField 
                                    runat="server" 
                                    AllowBlank="false" 
                                    MinDate="01.01.2006" 
                                    MinText="Can not have a start date before the Company existed." />   
                            </Editor>
                        </ext:DateColumn>
                        <ext:NumberColumn 
                            Header="Salary" 
                            DataIndex="salary" 
                            Format="$0,0.00" 
                            Width="100" 
                            Sortable="true">
                            <Editor>
                                <ext:NumberField 
                                    runat="server" 
                                    AllowBlank="false" 
                                    MinValue="1" 
                                    MaxValue="150000" 
                                    />
                            </Editor>
                        </ext:NumberColumn>
                        <ext:BooleanColumn 
                            Header="Active" 
                            DataIndex="active" 
                            Align="Center" 
                            Width="50" 
                            TrueText="Yes" 
                            FalseText="No">
                            <Editor>
                                <ext:Checkbox runat="server" />
                            </Editor>
                        </ext:BooleanColumn>
                    </Columns>
                </ColumnModel>
                <Listeners>
                    <AfterRender Fn="onAfterRender" />
                </Listeners>
            </ext:GridPanel>
        </form>  
    </body>
    </html>
  5. #5
    This is exactly it, just need to remove the buttons on the editor so the only way to save is to blur out of the row. I don't see properties for the buttons though, is there a way to find where they are being rendered and remove them completely so the rows are just editable and will save when you tab out of them or click to another row? You have that functionality working in the sample perfectly just want to remove the buttons.

    Thanks for any info...
  6. #6
    Please add the following script.

    Example
    <ext:ResourcePlaceHolder runat="server" />
    <script type="text/javascript">
        Ext.ux.grid.RowEditor.override({
            onRender : function () {
                Ext.ux.grid.RowEditor.superclass.onRender.apply(this, arguments);
                this.el.swallowEvent(['keydown', 'keyup', 'keypress']);
            }
        });
    </script>

Similar Threads

  1. Store AutoSave
    By cwolcott in forum 1.x Help
    Replies: 5
    Last Post: Jan 09, 2012, 11:26 PM
  2. [1.2] Postback on null values with autosave
    By hc.dev in forum 1.x Help
    Replies: 4
    Last Post: Jan 04, 2012, 4:52 PM
  3. Grid with AutoSave sample
    By PetrSnobelt in forum 1.x Help
    Replies: 3
    Last Post: Apr 27, 2011, 11:33 AM
  4. [CLOSED] autosave on gridpanel
    By Stefanaccio in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Feb 08, 2011, 2:42 PM
  5. [1.0] Examples Explorer | GridPanel > Update > AutoSave
    By r_honey in forum Open Discussions
    Replies: 3
    Last Post: Apr 29, 2010, 5:12 AM

Tags for this Thread

Posting Permissions