开发者

How to get the data from a row that was double-clicked in an ExtJS grid?

In an ExtJS grid, I can get the index of the selected data item like this:

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

But how do I get the index of the selected data item on double click?

When I do this:

listeners: {
    'rowdblclick': function(grid, rowindex, e){
        console.log(...);
    }
}

both grid and e don't seem to have the information I need and rowindex isn't useful since if the user resorts a column, then the index of the row do开发者_开发技巧uble-clicked is not necessarily the index of the dataset which loaded the grid.

Addendum

Thanks @McStretch, I ultimately solved the issue at hand by putting the id in the item list, hiding the id column, then sending the id to the edit page, like this:

listeners: {
    'rowdblclick': function(grid, index, rec){
        var id = grid.getSelectionModel().getSelected().json[0];
        go_to_page('edit_item', 'id=' + id);
    }
}


Index actually refers to the record's index in the store according to the documentation for cellClick:

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

If this is the case, then you shouldn't have to worry about grid reordering. I think you should get the index/record by using the above methodology in your 'rowdblclick' listener -- it's much more readable. Test it out and see what happens.


I found a way to do this:

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);
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜