How to skip over particular cells when tabbing through an Ext grid?

吃可爱长大的小学妹 提交于 2019-12-06 09:31:51

Just remove selType: "cellmodel" from the config. It will then default to rowmodel and the only thing that can be selected in the row are editable cells.

Look into overriding walkCells on the grid view.

Here's a really hacky way to skip the first column when tabbing through grid cells:

Ext.ComponentManager.create({
    viewConfig: {
        xhooks: {
            walkCells: function(pos, direction, e, preventWrap, verifierFn, scope) {
                return this.callParent([pos, direction, e, preventWrap, function(newPos) {
                    var newerPos = false;
                    if (newPos.column !== 0) {
                        return true;
                    }
                    newerPos = this.walkCells(newPos, direction, e, preventWrap);
                    if (newerPos) {
                        Ext.apply(newPos, newerPos);
                        return true;
                    }
                    return false;
                }, this]);
            }
        }
    }
 }, 'grid'); 

i found a solution to my problem so i'm sharing it here. try to use this as config in your current grid:

var grid = Ext.create('Ext.grid.Panel', {
    ...
    selModel: Ext.create('selection.cellmodel', {
        onEditorTab: function(editingPlugin, e) {
            var me = this,
                direction = e.shiftKey ? 'left' : 'right',
                position  = me.move(direction, e);

            if (position) {
                while(!editingPlugin.startEdit(position.row, position.column)){
                    position = me.move(direction, e);

                    // go to first editable cell
                    if(!position) editingPlugin.startEdit(0, 1); // TODO: make this dynamic
                }
                me.wasEditing = false;

            } else {
                // go to first editable cell
                if (editingPlugin.startEdit(0, 1)) { // TODO: make this dynamic
                    me.wasEditing = false;
                }
            }
        },
    }),
    //selType: 'cellmodel', // remove selType
    ...
})
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!