Ext-JS Grid - Remove Button - selModel

Hey, ich versuche bei meinem Grid einen Datensatz zu selektieren und dann zu löschen. Aber ich scheitere schon beim Selektieren. Klicke ich auf meinen Button erhalte ich folgende Fehlermeldung: Shopware.Plugins.OttschoPartnerSystem.Grid.selModel is undefined Das bezieht sich auf die Funktion: function confirmDelete(){ if(Shopware.Plugins.OttschoPartnerSystem.Grid.selModel.getCount() == 1) // only one president is selected here { Ext.MessageBox.alert('Confirmation','Do you not like that president at all?'); } else if(Shopware.Plugins.OttschoPartnerSystem.Grid.selModel.getCount() \> 1){ Ext.MessageBox.alert('Confirmation','Delete those presidents?'); } else { Ext.MessageBox.alert('Uh oh...','You can\'t really delete something you haven\'t selected huh?'); } } Grid: Ext.ns('Shopware.Plugins.OttschoPartnerSystem'); Shopware.Plugins.OttschoPartnerSystem.Grid = Ext.extend(Ext.grid.GridPanel, { region:'center', title:'Übersicht', id:'grid', renderTo:'table', view: new Ext.grid.GridView(), selModel: new Ext.grid.RowSelectionModel({ singleSelect:true }), initComponent: function() { this.initStore(); this.initColumnModel(); this.initTbar(); Shopware.Plugins.OttschoPartnerSystem.Grid.superclass.initComponent.call(this); }, initStore: function(){ this.store = new Ext.data.Store({ url: '{url action=getUnions}' , reader: new Ext.data.JsonReader({ root: 'items', totalProperty: 'total' }, [{ name: 'customernumber'},{ name: 'unionname'}, { name: 'unioncode'},{ name: 'percentage'}, { name: 'publicview'},{ name: 'firstname'},{ name: 'lastname'}]) }); this.store.load(); }, // inline toolbars initTbar: function(){ this.tbar = [{ text:'Add Something', tooltip:'Add a new row', iconCls:'add' },'-',{ text:'Remove Something', tooltip:'Remove the selected item', handler: confirmDelete, iconCls:'delete' }] }, initColumnModel: function(){ this.columns = [{ xtype: 'gridcolumn', dataIndex: 'customernumber', header: 'KDNR', sortable: true, width: 60 }, { xtype: 'gridcolumn', dataIndex: 'unionname', header: 'Verein', sortable: true, width: 150 }, { xtype: 'gridcolumn', dataIndex: 'firstname', header: 'Vorname', sortable: false, width: 120 }, { xtype: 'gridcolumn', dataIndex: 'lastname', header: 'Nachname', sortable: false, width: 120 }, { xtype: 'gridcolumn', dataIndex: 'unioncode', header: 'Verein-Code', sortable: false, width: 150 }, { xtype: 'gridcolumn', dataIndex: 'percentage', header: 'Porzentsatz', sortable: false, width: 80 }, { xtype: 'gridcolumn', dataIndex: 'publicview', header: 'sichtbar', sortable: false, width: 60 }]; } }); Ich finde den Fehler nicht. Was ist daran falsch? Danke

Hat hier noch jmd einen Tipp? Dieses ExtJS macht mich noch ganz verrückt :frowning:

Wieso packst du das confirmDelete nicht mit als Funktion direkt in das Objekt, dann kannst du doch mit this. direkt auf das SelectionModel zugreifen?

mhhh, theoretisch habe ich verstanden was du mir sagen willst, aber praktisch habe ich keine Ahnung wie ich es umsetzen soll :frowning: Gibt es dazu ein Beispiel? Ich schaue mir immer die Beispiele auf sencha.com an und versuche diese dann umzusetzen, was für mich leider nicht so einfach ist. meinst du in etwas so: intitDelete:function (){ if(this.selModel.getCount() == 1) // only one president is selected here { Ext.MessageBox.alert('Confirmation','Do you not like that president at all?'); } else if(this.selModel.getCount() \> 1){ Ext.MessageBox.alert('Confirmation','Delete those presidents?'); } else { Ext.MessageBox.alert('Uh oh...','You can\'t really delete something you haven\'t selected huh?'); } }

Ja, so müsste das theoretisch gehen.

okay, jetzt wird aber die Funktion direkt beim Laden ausgeführt. Und nicht erst wenn ich auf den Button klicke. Ext.ns('Shopware.Plugins.OttschoPartnerSystem'); Shopware.Plugins.OttschoPartnerSystem.Grid = Ext.extend(Ext.grid.GridPanel, { region:'center', title:'Übersicht', id:'grid', renderTo:'table', clicksToEdit:1, view: new Ext.grid.GridView(), selModel: new Ext.grid.RowSelectionModel({ singleSelect:false }), initComponent: function() { this.initStore(); this.initColumnModel(); this.initTbar(); Shopware.Plugins.OttschoPartnerSystem.Grid.superclass.initComponent.call(this); }, initStore: function(){ this.store = new Ext.data.Store({ url: '{url action=getUnions}' , reader: new Ext.data.JsonReader({ root: 'items', totalProperty: 'total' }, [{ name: 'customernumber'},{ name: 'unionname'}, { name: 'unioncode'},{ name: 'percentage'}, { name: 'publicview'},{ name: 'firstname'},{ name: 'lastname'}]) }); this.store.load(); }, // inline toolbars initTbar: function(){ this.tbar = [{ text:'Add Something', tooltip:'Add a new row', iconCls:'add' },'-',{ text:'Remove Something', tooltip:'Remove the selected item', handler: this.initDelete(), iconCls:'delete' }] }, initDelete: function() { if(this.selModel.getCount() == 1) { Ext.MessageBox.alert('Confirmation','Do you not like that president at all?'); } else if(this.selModel.getCount() \> 1) { Ext.MessageBox.alert('Confirmation','Delete those presidents?'); } else { Ext.MessageBox.alert('Uh oh...','You can\'t really delete something you haven\'t selected huh?'); } }, initColumnModel: function(){ this.columns = [{ xtype: 'gridcolumn', dataIndex: 'customernumber', header: 'KDNR', sortable: true, width: 60 }, { xtype: 'gridcolumn', dataIndex: 'unionname', header: 'Verein', sortable: true, width: 150 }, { xtype: 'gridcolumn', dataIndex: 'firstname', header: 'Vorname', sortable: false, width: 120 }, { xtype: 'gridcolumn', dataIndex: 'lastname', header: 'Nachname', sortable: false, width: 120 }, { xtype: 'gridcolumn', dataIndex: 'unioncode', header: 'Verein-Code', sortable: false, width: 150 }, { xtype: 'gridcolumn', dataIndex: 'percentage', header: 'Porzentsatz', sortable: false, width: 80 }, { xtype: 'gridcolumn', dataIndex: 'publicview', header: 'sichtbar', sortable: false, width: 60 }]; } });

Das kann aber eigentlich nicht - prüfe mal ob du diese Funktion irgendwo unabhängig noch zusätzlich aufrufst oder so?

Mir kommt es auch komisch vor. Aber direkt beim Aufruf der Form kommt die Meldung: Dafür dann aber beim Klick auf den “Delete” Button passiert nichts mehr. Hier der komplette Code der Datei. Ich kann nichts erkenne, wo ich die Funktion noch irgendwie aufrufe: [code] {extends file=“backend/index/parent.tpl”} {block name=“backend_index_css” append} {/block} {block name=“backend_index_body_inline”}

Hinweis Hier können Sie Vereine an vorhanden Kundenkonto's (Kundennummer) knüpfen, einen Vereincode festlegen und den dazugehörigen Prozentsatz. Vereine hinzufügen/definieren:
Kundennummer: Vereinname: Vereincode: Pozentsatz: Sichtbar:
Hinzufügen

{/block} [/code]

this.initDelete() - mach mal die Klammern weg :wink: Also einfach this.initDelete Außerdem dort noch scope: this, ergänzen.

Super, ich danke dir vielmals. jetzt muss ich nur noch rausfinden, wie ich von der selektierten Row die Informationen auslese (KDNR) und dann per SQL Query lösche :slight_smile: Dann habe ich mein ersten Grid mit Löschfunktion erstellt…