# Ext-JS Grid - Remove Button - selModel

**URL:** <https://forum.shopware.com/t/ext-js-grid-remove-button-selmodel/3504>\
**Category:** Shopware 3.5\
**Tags:** programming\
**Created:** [13. Juli 2011 um 09:30 UTC](https://forum.shopware.com/t/ext-js-grid-remove-button-selmodel/3504 "2011-07-13T09:30:21Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ottscho](https://avatars.discourse-cdn.com/v4/letter/o/7ba0ec/32.png) [@ottscho](https://forum.shopware.com/u/ottscho)\
**Post date:** [13. Juli 2011 um 09:30 UTC](https://forum.shopware.com/t/ext-js-grid-remove-button-selmodel/3504/1 "2011-07-13T09:30:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ottscho](https://avatars.discourse-cdn.com/v4/letter/o/7ba0ec/32.png) [@ottscho](https://forum.shopware.com/u/ottscho)\
**Post date:** [14. Juli 2011 um 09:30 UTC](https://forum.shopware.com/t/ext-js-grid-remove-button-selmodel/3504/2 "2011-07-14T09:30:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Stefan\_Hamann](https://avatars.discourse-cdn.com/v4/letter/s/5e9695/32.png) [@Stefan\_Hamann](https://forum.shopware.com/u/Stefan_Hamann)\
**Post date:** [14. Juli 2011 um 14:20 UTC](https://forum.shopware.com/t/ext-js-grid-remove-button-selmodel/3504/3 "2011-07-14T14:20:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ottscho](https://avatars.discourse-cdn.com/v4/letter/o/7ba0ec/32.png) [@ottscho](https://forum.shopware.com/u/ottscho)\
**Post date:** [14. Juli 2011 um 14:26 UTC](https://forum.shopware.com/t/ext-js-grid-remove-button-selmodel/3504/4 "2011-07-14T14:26:28Z")

</div>

mhhh, theoretisch habe ich verstanden was du mir sagen willst, aber praktisch habe ich keine Ahnung wie ich es umsetzen soll ☹ Gibt es dazu ein Beispiel? Ich schaue mir immer die Beispiele auf [sencha.com](http://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?'); } } `

---

<div class="post-metadata">

**Author:** ![Stefan\_Hamann](https://avatars.discourse-cdn.com/v4/letter/s/5e9695/32.png) [@Stefan\_Hamann](https://forum.shopware.com/u/Stefan_Hamann)\
**Post date:** [14. Juli 2011 um 14:33 UTC](https://forum.shopware.com/t/ext-js-grid-remove-button-selmodel/3504/5 "2011-07-14T14:33:48Z")

</div>

Ja, so müsste das theoretisch gehen.

---

<div class="post-metadata">

**Author:** ![ottscho](https://avatars.discourse-cdn.com/v4/letter/o/7ba0ec/32.png) [@ottscho](https://forum.shopware.com/u/ottscho)\
**Post date:** [14. Juli 2011 um 14:47 UTC](https://forum.shopware.com/t/ext-js-grid-remove-button-selmodel/3504/6 "2011-07-14T14:47:50Z")

</div>

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 }]; } }); `

---

<div class="post-metadata">

**Author:** ![Stefan\_Hamann](https://avatars.discourse-cdn.com/v4/letter/s/5e9695/32.png) [@Stefan\_Hamann](https://forum.shopware.com/u/Stefan_Hamann)\
**Post date:** [14. Juli 2011 um 15:17 UTC](https://forum.shopware.com/t/ext-js-grid-remove-button-selmodel/3504/7 "2011-07-14T15:17:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ottscho](https://avatars.discourse-cdn.com/v4/letter/o/7ba0ec/32.png) [@ottscho](https://forum.shopware.com/u/ottscho)\
**Post date:** [14. Juli 2011 um 15:33 UTC](https://forum.shopware.com/t/ext-js-grid-remove-button-selmodel/3504/8 "2011-07-14T15:33:40Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![Stefan\_Hamann](https://avatars.discourse-cdn.com/v4/letter/s/5e9695/32.png) [@Stefan\_Hamann](https://forum.shopware.com/u/Stefan_Hamann)\
**Post date:** [14. Juli 2011 um 15:48 UTC](https://forum.shopware.com/t/ext-js-grid-remove-button-selmodel/3504/9 "2011-07-14T15:48:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ottscho](https://avatars.discourse-cdn.com/v4/letter/o/7ba0ec/32.png) [@ottscho](https://forum.shopware.com/u/ottscho)\
**Post date:** [14. Juli 2011 um 19:28 UTC](https://forum.shopware.com/t/ext-js-grid-remove-button-selmodel/3504/10 "2011-07-14T19:28:50Z")

</div>

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 🙂 Dann habe ich mein ersten Grid mit Löschfunktion erstellt…
