1

I have set 'enableTextSelectionOnCells' option to true to select text in slickgrid but I can only select text in IE and chrome but not in firefox. I know this is bug in slickgrid and it had been fixed in slickgrid 2.2 but I am using slickgrid V2.1 and don't want to upgrade to V2.2. Is there any way to select text in firefox using slickgrid 2.1

  • well actually I don't find it bullet proof either in 2.2, even if I updated to the last version just now it still not fully working. It doesn't work if I do double-clicking on text and text selection not always work. – ghiscoding Nov 22 '13 at 03:54

1 Answers1

3

I had the same problem as you have and I finally found the solution from a pull request made by the user icoxfog417 (thanks mate), the pull request is not yet approved (hopefully soon) but I tried it and it works on all 3 browsers which I tried (in my case FF27, IE8, Chrome31). You do have to modify 1 of the core file slick.grid.js but it's worth it :)
The pull request is this one: Pull Request #746: fix issue#739

The code change is simple and looks like this:
Modify the file slick.grid.js at line 2236, replace the code with this:

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

then insert at line 2418 (after the setFocus() function), insert this new code:

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

Voilà!!! Quite happy about it :)

ghiscoding
  • 12,308
  • 6
  • 69
  • 112