angular-ui / ui-sortable

jQuery UI Sortable for AngularJS
http://angular-ui.github.io/ui-sortable/
MIT License
1.26k stars 441 forks source link

How to allow text to be copied in a ui-sortable table? #522

Closed imTachu closed 7 years ago

imTachu commented 7 years ago

I'm sorry if this has been addressed before, I couldn't find it. I want to allow users to copy the text inside the rows of a ui-sortable table. In specific in this case, the pn-custom directive only contains a span with text. That is the text I want to allow to be copied.

<table class="table">
       <thead>
          <tr>
             <th>Column 1</th>
             <th>Column 2</th>
             <th>Column 3</th>
          </tr>
       </thead>
       <tbody ui-sortable="sortableOptions" ng-model="aModel">
          <tr ng-repeat="prwd in aModel">
             <td><pn-custom id="{{prwd.article_id}}"></pn-custom></td>
             <td>{{prwd.label}}</td>
             <td>{{prwd.attribute}}</td>
          </tr>
       </tbody>
    </table>

Of what I've read in the README file, I should use a cancel? Is this wrong? Is there any simple way to achieve this that I'm ignoring?

$scope.sortableOptions = {
  update: function(e, ui) {
    if (ui.item.sortable.span) {
      ui.item.sortable.cancel();
    }
  }
};

The reason why I post this here and not in SO is because if I think this is a simple use case, and if I can fix I would like to document it in the README.md file.

thgreasi commented 7 years ago

Does the directive handle the coping part or you just need to select the text? I think that you might need to use a handle. If you actually need to check the DOM element that was clicked, you can do something like if ($(e.originalEvent.target).is('span')) { /*...*/ }. But, since cancel() only reverts the sorting after the dragging, you might want to take a look at the cancel option as well.

thgreasi commented 7 years ago

Any feedback on this?

imTachu commented 7 years ago

So sorry! I forgot to tell you, it was solved like this:

<tbody ui-sortable="sortableOptions" ng-model="aModel">

  $scope.sortableOptions = {
    cancel: 'pn-custom id, .input-sm'
  };

To me, it looks very clean and works very well:

WDYT?

thgreasi commented 7 years ago

Yea, that's exactly what I was thinking of. 👍 for making it work and 👍 for sharing back your findings.