-
10 Apr 2012 1:01 AM #1
Can't get selected row from grid
Can't get selected row from grid
Hello. For two days i try to resolve the problem and i didn't find the response.
On the above code, how can i get the selected row when you click the button Remove subpage? I tryed with getSelectionModel() but i get an error.
Thanks
Wait your response.
Code:listTextSubPages: { //list subpages title: 'Subpages List', id: 'listSubpages', layout: 'fit', bodyPadding: 0, items: [ Ext.create('Ext.grid.Panel', { itemId:'gridSubpagesList', columns: [ {text: "ID", dataIndex: 'objid', align: 'center', width:50, hidden: true}, {text: "Name", width: 200, dataIndex: 'name', sortable: true}, {text: "Short Description", flex: 1, width: 380, dataIndex: 'sDescription', sortable: true}, {text: "Last update", width: 130, dataIndex: 'lastUpdate', sortable: true} ], store : new Ext.data.JsonStore({ storeId:'storeTextSubPages', fields:['objid','name', 'sDescription', 'lastUpdate'], autoLoad: true, proxy:{ url:'showtextsubpages/cities', type:'ajax', reader:{ root:'data', type:'json' } } }), listeners: { itemdblclick:function(view, record, item, index, e ) { var rowID = record.get('objid'); Ext.getCmp('content-panel').layout.setActiveItem('edit-subPages-panel');//load subpages list param=getSelectedMenu(); var content=Ext.getCmp('edit-subPages-panel'); content.down('form').getForm().load({url:'showtextsubpages/'+param+'/'+rowID}); } } }) ], dockedItems: [ { xtype: 'toolbar', ignoreParentFrame: true, ignoreBorderManagement: true, cls: 'absolute-form-toolbar', items: [ { text: 'Add subpage', iconCls: 'icon-add', handler:function(){ Ext.MessageBox.prompt('Insert new data', 'Please enter the name:', showResultText); function showResultText(btn, text){//add data var param=getSelectedMenu(); Ext.Ajax.request({ url: 'showtextsubpagesadd', success: function(){ }, // function called on success failure: function(){ }, params: { param: param, action: btn, name:text } // your json data }); }; }, },{ text: 'Remove subpage', iconCls: 'icon-remove', handler: function() { //gere is the problem } } ] } ] }
-
10 Apr 2012 4:54 AM #2
There are several methods:
Regards,Code:myGrid.getSelectionModel().getSelection()[0]; // for use in button // global listener for class this.grid.getSelectionModel().on('select', function(selModel, model, idx) { // your code here }, this);
Scott.
-
10 Apr 2012 5:08 AM #3
thanks for helping me!
so, if i put
i get the message:Code:handler: function() { var grid = this.grid.getSelectionModel().getSelection()[0]; console.log(grid); }
TypeError: Cannot call method 'getSelectionModel' of undefined [http://www.mallorcainfo.de/media/ExtJS/resources1/js/textPages.js:214]if i try:i get the error:Code:handler: function() { var grid = Ext.getCmp('listSubpages').getSelectionModel().getSelection()[0]; console.log(grid); }
TypeError: Object [object Object] has no method 'getSelectionModel' [http://www.mallorcainfo.de/media/ExtJS/resources1/js/textPages.js:214]
-
10 Apr 2012 5:37 AM #4
You are getting the id of your listTextSubPages (id: 'listSubpages',)
You will need to get your grid. I see you have itemId, so you will need to get that .. something like:
You can use firebug to view the values of each using breakpoints or console.log and see what is going on in the code.Code:var list = Ext.getCmp('listSubpages'); // getting id var grid = list.down('#gridSubpagesList'); // using itemid of grid var row = grid.getSelectionModel().getSelection()[0];
Regards,
Scott.
-
10 Apr 2012 6:54 AM #5
perfect, worked.
i get then the values with var id=sm.get('objid');
Thanks alotScott! I will do the rest (deleting from database). Hope will be no problem
-
17 Apr 2012 9:13 AM #6
Hello again.
I still have a little problem.
I want, when i press the button Add subpage, to add data to database and into grid.
So, i made to add into database, the problem, is that i want to show the data instantly and in the grid.
So, to do this, i tried:
but won't refresh it...and is not any errorCode:success: function(){ var list = Ext.getCmp('listSubpages'); // getting id var grid = list.down('#gridSubpagesList'); // using itemid of grid grid.getView().refresh(true); }
-
17 Apr 2012 9:17 AM #7
Try: grid.store.load();
Scott.
-
19 Apr 2012 4:06 AM #8
-
16 Jan 2013 11:22 PM #9
Thank you Mr.scott ..
Thank you Mr.scott ..
thank you scottmartin and fabbydesign .. your discussion helped me to solve my problem ..



Reply With Quote