Ext.Net:GridPanel with RowEditor Plugin

时间:2013-06-08 12:26:51

标签: extjs ext.net

当点击插入按钮(btnSinifEkle)时,我的事件通过OnBeforeRecordInserted =“tetikle4”触发。甚至我点击取消按钮,它已经通过OnBeforeRecordInserted插入并显示在网格内。我怎么能避免这个。当我点击插入按钮,记录显示在网格内,甚至我不告诉更新或取消。

非常感谢你。

<ext:XScript ID="XScript1" runat="server">
        <script>
            var sinifEkle = function () {
                var grid = #{gridSinif};
                grid.editingPlugin.cancelEdit();

                // Create a record instance through the ModelManager
                var r = Ext.ModelManager.create({
                    SinifAd: 'yeni sınıf',

                }, 'Sinif');

                grid.store.insert(0, r);
                grid.editingPlugin.startEdit(0, 0);
            };

            var sinifSil = function () {
                var grid = #{gridSinif},
                    sm = grid.getSelectionModel();

                grid.editingPlugin.cancelEdit();
                grid.store.remove(sm.getSelection());
                if (grid.store.getCount() > 0) {
                    sm.select(0);
                }
            };
        </script>
    </ext:XScript>                


  <ext:GridPanel ID="gridSinif" runat="server" Width="250" Height="300" Title="Sınıf tanımlama"
                                    Frame="true">
                                    <Store>
                                        <ext:Store ID="SinifStore" runat="server" AutomaticResponseValues="false" OnAfterStoreChanged="tetikle"
                                            OnBeforeRecordUpdated="tetikle1" OnBeforeRecordDeleted="tetikle3" AutoSync="true" OnBeforeRecordInserted="tetikle4">
                                            <Model>
                                                <ext:Model ID="Model1" runat="server" IDProperty="SinifId" Name="Sinif">
                                                    <Fields>
                                                        <ext:ModelField Name="SinifId" Type="Int" />
                                                        <ext:ModelField Name="SinifAd" Type="String" />
                                                    </Fields>
                                                </ext:Model>
                                            </Model>
                                        </ext:Store>
                                    </Store>
                                    <Plugins>
                                        <ext:RowEditing ID="RowEditing1" runat="server" ClicksToMoveEditor="1" AutoCancel="false" />
                                    </Plugins>
                                    <TopBar>
                                        <ext:Toolbar ID="Toolbar1" runat="server">
                                            <Items>
                                                <ext:Button ID="btnSinifEkle" runat="server" Text="Sınıf ekle" Icon="Add">
                                                    <Listeners>
                                                        <Click Fn="sinifEkle" />
                                                    </Listeners>
                                                </ext:Button>
                                                <ext:Button ID="btnSinifSil" runat="server" Text="Sınıf sil" Icon="Delete" Disabled="true">
                                                    <Listeners>
                                                        <Click Fn="sinifSil" />
                                                    </Listeners>
                                                </ext:Button>
                                            </Items>
                                        </ext:Toolbar>
                                    </TopBar>
                                    <ColumnModel ID="ColumnModel1" runat="server">
                                        <Columns>
                                            <ext:Column ID="Column1" runat="server" Text="ID" DataIndex="SinifId" Width="35" />
                                            <ext:Column ID="Column3" runat="server" Text="Sınıf adı" DataIndex="SinifAd" Flex="1">
                                                <Editor>
                                                    <ext:TextField runat="server" />
                                                </Editor>
                                            </ext:Column>
                                        </Columns>
                                    </ColumnModel>
                                    <Listeners>
                                        <SelectionChange Handler="#{btnSinifSil}.setDisabled(!selected.length);" />
                                    </Listeners>
                                </ext:GridPanel>

1 个答案:

答案 0 :(得分:1)

此处调用商店的OnBeforeRecordInserted:

grid.store.insert(0, r);

因为您设置了AutoSync =“true”。

为避免这种情况,您应该设置AutoSync =“false”并在需要时调用Store的同步方法(客户端)。