0

我正在使用 Ext.grid.GridPanel 从商店中填充我的商品。一切都很好,但我有一个问题。

当我ctrl在网格行上按 + 鼠标单击时,该行取消选择。我怎么能阻止这个动作?

我试过在鼠标点击事件和按键事件上编写函数

this.grid.onClick = function(event){
            if (event.ctrlKey === true){
                event.preventDefault();
                event.stopPropagation();
            }
        };

也尝试过写作return false;event.preventDefault(); event.stopPropagation();但没有运气。

有什么建议么?

4

1 回答 1

0

找到了一种解决方法。

在 RowSelectionModel.js 中有自定义函数handleMouseDown

handleMouseDown : function(g, rowIndex, e){
    if(e.button !== 0 || this.isLocked()){
        return;
    }
    var view = this.grid.getView();
    if(e.shiftKey && !this.singleSelect && this.last !== false){
        var last = this.last;
        this.selectRange(last, rowIndex, e.ctrlKey);
        this.last = last; // reset the last
        view.focusRow(rowIndex);
    }else{
        var isSelected = this.isSelected(rowIndex);
        if(e.ctrlKey && isSelected){
            this.deselectRow(rowIndex);
        }else if(!isSelected || this.getCount() > 1){
            this.selectRow(rowIndex, e.ctrlKey || e.shiftKey);
            view.focusRow(rowIndex);
        }
    }
},

有线条

if(e.ctrlKey && isSelected){
  this.deselectRow(rowIndex);
}

所以我需要重写这个函数并在上面提到的 if 中添加一些自定义操作。

于 2013-05-02T11:41:50.557 回答