SamD SamD - 6 months ago 162
AngularJS Question

How to enable text selection in angular ui grid with row selection enabled

I am using ui-grid v3.1.1 and have enabled rowSelection. I notice that when I enable row selection, I can no longer select (click-hold-drag) text from the rows.

I noticed the same behaviour in the example in their tutorials (second grid on the page).

It would be great to know if there is some work around by which I can still allow the user to select text, while the rowSelection is enabled.

Here is a plunkr link to the example from the tutorial.

$scope.gridOptions = {
enableRowSelection: true,
enableRowHeaderSelection: false
};

Answer

A previous SO answer by @Aman Mahajan offers a fix:

A ui-grid-disable-selection class is added to the grid when both enableRowSelection and enableFullRowSelectionare enabled (can check ui-grid v3.1.1 source in selection.js ~line 903). So you can override the CSS class by adding a specific class to your grid, for example ui-grid-selectable.

<div ui-grid="gridOptions" ui-grid-selection class="grid ui-grid-selectable"></div>

And in your CSS:

.ui-grid-selectable .ui-grid-disable-selection {
     -webkit-touch-callout: default;
     -webkit-user-select: text;
     -khtml-user-select: text;
     -moz-user-select: text;
     -ms-user-select: text;
     user-select: text;
     cursor:auto;
 }

Here's the forked plunker with the added CSS class to override the default behavior.