我已将'enableTextSelectionOnCells'选项设置为true以在slickgrid中选择文本,但我只能在IE和Chrome中选择文本,但不能在firefox中选择。我知道这是slickgrid中的错误,它已在slickgrid 2.2中修复但我使用slickgrid V2.1并且不想升级到V2.2。有没有办法在使用slickgrid 2.1
的firefox中选择文本答案 0 :(得分:3)
我遇到了同样的问题,我终于找到了用户提出的解决方案 icoxfog417 (感谢队友),拉请求不是尚未批准(希望很快),但我尝试了它,它适用于我尝试的所有3个浏览器(在我的情况下FF27,IE8,Chrome31)。你必须修改核心文件slick.grid.js
中的一个,但这是值得的:)左拉请求是这样的:Pull Request #746: fix issue#739
代码更改很简单,如下所示:
修改第2236行的文件slick.grid.js
,将代码替换为:
// if this click resulted in some cell child node getting focus,
// don't steal it back - keyboard events will still bubble up
// IE9+ seems to default DIVs to tabIndex=0 instead of -1, so check for cell clicks directly.
if (e.target != document.activeElement || $(e.target).hasClass("slick-cell")) {
var selection = getTextSelection(); //store text-selection and restore it after
setFocus();
setTextSelection(selection);
}
然后在第2418行插入(在setFocus()
函数之后),插入以下新代码:
//This get/set methods are used for keeping text-selection. These don't consider IE because they don't loose text-selection.
function getTextSelection(){
var textSelection = null;
if (window.getSelection) {
var selection = window.getSelection();
if (selection.rangeCount > 0) {
textSelection = selection.getRangeAt(0);
}
}
return textSelection;
}
function setTextSelection(selection){
if (window.getSelection && selection) {
var target = window.getSelection();
target.removeAllRanges();
target.addRange(selection);
}
}
瞧!!!非常高兴:)