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

In ExtJS grid, I can get the index of the selected data item as follows:

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 gridand e, it seems, do not have the necessary information, but are rowindexnot useful, because if the user resorts to a column, then the double-row row index is not necessarily equal to the index of the data set that loaded the grid.

Adding

Thanks @McStretch, I eventually solved the problem by putting idin the list of elements, hiding the identifier column, and then sending the identifier to the edit page, for example:

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

cellClick:

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

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

, . , /, 'rowdblclick' - . , .

+9

:

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

Source: https://habr.com/ru/post/1779207/


All Articles