如何从ExtJS网格中双击的行中获取数据?

如何从ExtJS网格中双击的行中获取数据?,extjs,grid,Extjs,Grid,在ExtJS网格中,我可以获得所选数据项的索引,如下所示: grid.getSelectionModel().on('rowselect', function(sm, index, rec){ changeMenuItemInfoArea(menuItemApplication, 'you are on row with index ' + index); var row_number_parts = rec.id.split('-'); // rec.id = e.g. "ex

在ExtJS网格中,我可以获得所选数据项的索引,如下所示:

grid.getSelectionModel().on('rowselect', function(sm, index, rec){
    changeMenuItemInfoArea(menuItemApplication, 'you are on row with index ' + index);
    var row_number_parts = rec.id.split('-'); // rec.id = e.g. "ext-record-1"
    var selected_index = row_number_parts[2] - 1;
    alert(selected_index);
});
listeners: {
    'rowdblclick': function(grid, index, rec){
        var id = grid.getSelectionModel().getSelected().json[0];
        go_to_page('edit_item', 'id=' + id);
    }
}
但如何在双击时获取所选数据项的索引?

当我这样做时:

listeners: {
    'rowdblclick': function(grid, rowindex, e){
        console.log(...);
    }
}
grid
e
似乎都没有我需要的信息,
rowindex
也没有用处,因为如果用户引用列,则双击的行的索引不一定是加载网格的数据集的索引

补遗 感谢@McStretch,我最终解决了手头的问题,将
id
放在项目列表中,隐藏id列,然后将id发送到编辑页面,如下所示:

grid.getSelectionModel().on('rowselect', function(sm, index, rec){
    changeMenuItemInfoArea(menuItemApplication, 'you are on row with index ' + index);
    var row_number_parts = rec.id.split('-'); // rec.id = e.g. "ext-record-1"
    var selected_index = row_number_parts[2] - 1;
    alert(selected_index);
});
listeners: {
    'rowdblclick': function(grid, index, rec){
        var id = grid.getSelectionModel().getSelected().json[0];
        go_to_page('edit_item', 'id=' + id);
    }
}

我找到了这样做的方法:

listeners: {
    'rowdblclick': function(grid, index, rec){
        var row_label = grid.getSelectionModel().getSelected().id;
        var row_label_parts = row_label.split('-');
        var selected_index = row_label_parts[2] - 1;
        alert(selected_index);
    }
}

根据
cellClick
,Index实际上是指存储区中记录的索引:

function(grid, rowIndex, columnIndex, e) {
    // Get the Record, this is the point at which rowIndex references a 
    // record's index in the grid's store.
    var record = grid.getStore().getAt(rowIndex);  

    // Get field name
    var fieldName = grid.getColumnModel().getDataIndex(columnIndex); 
    var data = record.get(fieldName);
}

如果是这种情况,那么就不必担心网格重新排序。我认为您应该通过在
'rowdblclick'
侦听器中使用上述方法来获取索引/记录--它更具可读性。测试一下,看看会发生什么。

不要这样做。即使在排序之后,索引也是正确的。排序是在存储级别处理的,因此索引将在存储和网格之间匹配。