nkuhta
nkuhta

Reputation: 11128

Take CellEditing plugin from editor listeners

I have the grid with cell editing. When someone press enter in the celleditor - extjs need to open editor in next row and same cell. I know, that this action does startEdit() method of CellEditing class. But how can I access CellEditing of that grid from listener of CellEditor.

listeners:{
    specialkey: function(field, e){
        if (e.getKey() == e.ENTER) {
            var grid = Ext.getCmp('sheetproductionrestin');
            var store = Ext.getCmp('sheetproductionrestin').store;
            var selModel = grid.getSelectionModel();
            var selectedRecord = selModel.getLastSelected();

            var recordIndex = store.indexOf(selectedRecord);
            var nextRecord = store.getAt(recordIndex + 1);
            selModel.select(nextRecord);
        }
    }
}

This code makes next row focused, but how can I access Editing Plugin and call StartEdit from here?

Upvotes: 3

Views: 5599

Answers (2)

Sasha Brocato
Sasha Brocato

Reputation: 673

Usually what I do is just store a reference to the cell editing plugin like this:

myGrid.cellEditor = Ext.create('Ext.grid.plugin.CellEditing');

Then you can assign it to the grid like this:

var myGrid = Ext.create('Ext.grid.Panel',{
    plugins: [myGrid.cellEditor]

Then when you need to start the edit you can call myGrid.cellEditor.startEdit(colNumber)

Upvotes: 0

Molecular Man
Molecular Man

Reputation: 22386

You can access plugin via getPlugin method provided you have assigned pluginId to your plugin:

var grid = Ext.create('Ext.grid.Panel',{
    plugins: [Ext.create('Ext.grid.plugin.CellEditing', {
        clicksToEdit: 2,
        pluginId: 'cellplugin'
    })],
    columns: [
        {
        header: 'Name',
        dataIndex: 'name',
        editor: {
            xtype: 'textfield',
            listeners: {
                specialkey: function(field, e) {
                    if (e.getKey() == e.ENTER) {
                        var grid = Ext.getCmp('sheetproductionrestin');
                        var store = Ext.getCmp('sheetproductionrestin').store;
                        var selModel = grid.getSelectionModel();
                        var selectedRecord = selModel.getLastSelected();

                        var recordIndex = store.indexOf(selectedRecord);
                        var nextRecord = store.getAt(recordIndex + 1);
                        selModel.select(nextRecord);

                        var plugin = grid.getPlugin('cellplugin');
                        plugin.startEdit(nextRecord, grid.columns[0]);
                    }
                }
            }
        }},
        // ...
    ],
    // ...
});

Here is jsfiddle (the first column is editable).

Upvotes: 3

Related Questions