[CLOSED] How to cancel current edition anc hide row editor when button DirectEvent is raised

  1. #1

    [CLOSED] How to cancel current edition anc hide row editor when button DirectEvent is raised

    Hi folks,

    based on this example I'm into an issue. Steps to reproduce:

    1. Press Add button
    2. Press Refresh button

    Row editor is still visible. How can I really stop editing and hide it when I press any button that raises a DirectEvent?

    Cheers

    Click image for larger version. 

Name:	error.png 
Views:	131 
Size:	11.6 KB 
ID:	4692

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <script runat="server">    
        protected void Page_Load(object sender, EventArgs e)
        {
            SetStoreTables();
        }
    
        protected void btnResetPage_Click(object sender, DirectEventArgs e)
        {
            gridCriteria.StopEditing();
            X.MessageBox.Alert("", "page reset").Show();
        }
    
        private void SetStoreTables()
        {
            System.Collections.Generic.List<object> data = new System.Collections.Generic.List<object>();
            data.Add(new { Description = "TABLE_1" });
            data.Add(new { Description = "TABLE_2" });
            Store s1 = this.cboTables.GetStore();
            s1.DataSource = data;
            s1.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 id="Head1" runat="server">
        <title></title>
        <ext:XScript ID="XScript1" runat="server">        
        <script type="text/javascript">
            var GroupByRenderer = function (value) {
                var r = StoreGroupBy.getById(value);
                if (Ext.isEmpty(r)) {
                    return "";
                }
                return r.data.Description;
            };
    
            var OrderTypeRenderer = function (value) {
                var r = StoreOrderType.getById(value);
                if (Ext.isEmpty(r)) {
                    return "";
                }
                return r.data.Description;
            };
            var NewRow = function () {
                btnNewRow.disabled = true;
                gridCriteria.getRowEditor().stopEditing();
                var s = StoreCriteria.save();
                var rowIndex = gridCriteria.addRecord({
                    Table: "",
                    Column: ""
                });
                gridCriteria.getView().refresh();
                gridCriteria.getSelectionModel().selectRow(rowIndex);
                gridCriteria.getRowEditor().startEditing(rowIndex);
            }
    
            var CancelEdition = function () {
                if (this.record.newRecord) {
                    this.grid.getStore().remove(this.record);
                    this.grid.getView().refresh();
                }
                btnNewRow.disabled = false;
            }
    
            var BeforeEdition = function () {
                btnNewRow.disabled = true;
            }
    
            var UpdateEdition = function () {
                if (this.record.newRecord) {
                    this.record.newRecord = false;
                    this.record.dirty = false;
                }
                btnNewRow.disabled = false;
            }                    
        </script>    
        </ext:XScript>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        <ext:Store ID="StoreCriteria" runat="server" RefreshAfterSaving="None">
            <Reader>
                <ext:JsonReader IDProperty="Id">
                    <Fields>
                        <ext:RecordField Name="Id" Type="String" />
                        <ext:RecordField Name="Table" Type="String" />
                        <ext:RecordField Name="Column" Type="String" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
        </ext:Store>
        <ext:Panel ID="pnlContenedor" runat="server">
            <TopBar>
                <ext:Toolbar ID="Toolbar1" runat="server" Flat="true">
                    <Items>
                        <ext:Button ID="btnNewRow" runat="server" Icon="Add" ToolTip="ADD">
                            <Listeners>
                                <Click Fn="NewRow" />
                            </Listeners>
                        </ext:Button>
                        <ext:Button ID="btnResetPage" runat="server" Icon="ArrowRefresh" ToolTip="REFRESH">
                            <DirectEvents>
                                <Click OnEvent="btnResetPage_Click" ViewStateMode="Enabled" />
                            </DirectEvents>
                        </ext:Button>
                    </Items>
                </ext:Toolbar>
            </TopBar>
            <Items>
                <ext:GridPanel ID="gridCriteria" runat="server" AutoWidth="true" Height="300" StoreID="StoreCriteria">
                    <ColumnModel ID="ColumnModel1" runat="server">
                        <Columns>
                            <ext:RowNumbererColumn />
                            <ext:Column ColumnID="Table" DataIndex="Table" Editable="true" Hideable="false" Sortable="false"
                                Resizable="true" Width="100" Header="Tabla">
                                <Editor>
                                    <ext:ComboBox runat="server" ID="cboTables" DisplayField="Description" ValueField="Description">
                                        <Store>
                                            <ext:Store ID="Store2" runat="server">
                                                <Reader>
                                                    <ext:JsonReader IDProperty="Description">
                                                        <Fields>
                                                            <ext:RecordField Name="Description" Type="String" />
                                                            <ext:RecordField Name="Description" Type="String" />
                                                        </Fields>
                                                    </ext:JsonReader>
                                                </Reader>
                                            </ext:Store>
                                        </Store>
                                    </ext:ComboBox>
                                </Editor>
                            </ext:Column>
                            <ext:Column ColumnID="Column" DataIndex="Column" Editable="true" Hideable="false"
                                Sortable="false" Resizable="true" Width="100" Header="Columna">
                                <Editor>
                                    <ext:TextField ID="TextField1" runat="server" />
                                </Editor>
                            </ext:Column>
                        </Columns>
                    </ColumnModel>
                    <Plugins>
                        <ext:RowEditor ID="RowEditor1" runat="server" SaveText="Update">
                            <Listeners>
                                <BeforeEdit Fn="BeforeEdition" />
                                <AfterEdit Fn="UpdateEdition" />
                                <CancelEdit Fn="CancelEdition" />
                            </Listeners>
                        </ext:RowEditor>
                    </Plugins>
                    <SelectionModel>
                        <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" />
                    </SelectionModel>
                </ext:GridPanel>
            </Items>
        </ext:Panel>
        </form>
    </body>
    </html>
    Last edited by Daniil; Sep 03, 2012 at 5:02 PM. Reason: [CLOSED]
  2. #2
    Hi,

    To cancel editing please call:
    RowEditor1.stopEditing(false); // false - to do not save changes, i.e. cancel.
    You can call it within a Before handler of the DirectEvent.

Similar Threads

  1. Replies: 1
    Last Post: Aug 29, 2012, 12:28 PM
  2. Replies: 2
    Last Post: Jun 06, 2012, 1:17 PM
  3. [CLOSED] Cancel editor
    By rthiney in forum 1.x Premium Help
    Replies: 1
    Last Post: Jun 22, 2011, 5:56 PM
  4. Replies: 0
    Last Post: Nov 20, 2009, 3:24 AM
  5. Replies: 3
    Last Post: Oct 26, 2009, 12:48 PM

Posting Permissions