Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Extjs4 Ext.grid.Panel从tbar按钮获取所选记录_Extjs4 - Fatal编程技术网

Extjs4 Ext.grid.Panel从tbar按钮获取所选记录

Extjs4 Ext.grid.Panel从tbar按钮获取所选记录,extjs4,Extjs4,我创建了一个视图扩展Ext.grid.Panel,并在其上附加了一个tbar,在工具栏上有两个按钮[Add]和[Remove],在这个问题中,我只关注[Remove]命令 像往常一样,我想保留我要删除的网格中当前选定的记录 因此,在控制器中: init: function() { this.control({ 'extendgridlist button[action=remove]': { click: this.removeCurrentRow; } }); }

我创建了一个视图扩展Ext.grid.Panel,并在其上附加了一个tbar,在工具栏上有两个按钮[Add]和[Remove],在这个问题中,我只关注[Remove]命令

像往常一样,我想保留我要删除的网格中当前选定的记录

因此,在控制器中:

init: function() {
 this.control({
   'extendgridlist button[action=remove]': {
      click: this.removeCurrentRow;
    }
 });
}

removeCurrentRow: function(t){
 // how do i get current selected record
}

“nscrob”的答案应该很好,我只是想指出另一种方法。每个Ext组件都可以有一个“id”字段。因此,如果在网格创建时为其提供了如下配置选项:

id:'my_grid_id'
然后,从removeCurrentRow函数内的任何位置执行以下操作:

var grid = Ext.getCmp('my_grid_id');
var rows = grid.getSelectionModel().getSelection();
if(!rows.length)
{   //in case this fires with no selection
    alert("No Rows Selected!");
    return;
}
var row = rows[0];

正如我所说,与其他答案类似,但只是访问网格的另一种方式。

nscrob的答案应该很好,我只是想指出另一种方法。每个Ext组件都可以有一个“id”字段。因此,如果在网格创建时为其提供了如下配置选项:

id:'my_grid_id'
然后,从removeCurrentRow函数内的任何位置执行以下操作:

var grid = Ext.getCmp('my_grid_id');
var rows = grid.getSelectionModel().getSelection();
if(!rows.length)
{   //in case this fires with no selection
    alert("No Rows Selected!");
    return;
}
var row = rows[0];

正如我所说,与其他答案类似,但只是访问网格的另一种方式。

如果网格是
selType=“cellModel”
使用下面的代码:

var grid = Ext.getCmp('id-of-grid');
var recid = grid.getSelectionModel().getCurrentPosition();

if(recid && recid.row){
  var r = grid.getStore().getAt(recid.row)   
  alert(r.data.anyofgridfieldid)
}

更多详细信息:

如果网格要
selType=“cellModel”
使用以下代码:

var grid = Ext.getCmp('id-of-grid');
var recid = grid.getSelectionModel().getCurrentPosition();

if(recid && recid.row){
  var r = grid.getStore().getAt(recid.row)   
  alert(r.data.anyofgridfieldid)
}
更多详情: