javascript - How to change position on a selected table -


i'm trying make selectable table. before changing position in row, row has selectable.

how can that?

here have:

angular.module("tablemoveupdown",[]).component("tablemoveupdown", {  	templateurl: "./js/componente/table-move-up-down/table-move-up-down.template.html",  	controller: function($scope){          $scope.items = [              { title: "alvaro" },              { title: "juan" },              { title: "pedro" },              { title: "david" },              { title: "walter" },          ];            var move = function (origin, destination) {              var temp = $scope.items[destination];              $scope.items[destination] = $scope.items[origin];              $scope.items[origin] = temp;          };            $scope.moveup = function(index){              move(index, index - 1);          };            $scope.movedown = function(index){              move(index, index + 1);          };      }  })
<div>      <table class="table table-bordered table-striped table-hover table-condensed">      <thead><th>index</th><th>amigos</th><th>función subir</th><th>función bajar</th></thead>      <tr ng-repeat="item in items">        <td>{{$index}}</td>        <td>{{item.title}}</td>        <td><span ng-show="!$first" ng-click="moveup($index)"                  class="glyphicon glyphicon-arrow-up">subir</span></td>        <td><span ng-show="!$last" ng-click="movedown($index)"                  class="glyphicon glyphicon-arrow-down">bajar</span></td>      </tr>    </table>    </div>

you can save selected index , use ng-class , ng-click update selected row adding logic move function. working example: https://plnkr.co/edit/0375uuvkwso0rxt6en1n?p=preview

component js

angular.module("tablemoveupdown", []).component("tablemoveupdown", {   templateurl: "tablecomp.html",   controller: function($scope) {     $scope.items = [{       title: "alvaro"     }, {       title: "juan"     }, {       title: "pedro"     }, {       title: "david"     }, {       title: "walter"     }, ];      $scope.selectedindex = 0;      var move = function(origin, destination) {       if (origin != $scope.selectedindex)         return;       var temp = $scope.items[destination];       $scope.items[destination] = $scope.items[origin];       $scope.items[origin] = temp;     };      $scope.moveup = function(index) {       move(index, index - 1);     };      $scope.movedown = function(index) {       move(index, index + 1);     };   } }) 

component html

<div>    <table class="table table-bordered table-striped table-hover table-condensed">     <thead>       <th>index</th>       <th>amigos</th>       <th>función subir</th>       <th>función bajar</th>     </thead>     <tr ng-repeat="item in items" ng-click="$parent.selectedindex = $index" ng-class="{'selected': $index === $parent.selectedindex}">       <td>{{$index}}</td>       <td>{{item.title}}</td>       <td><span ng-show="!$first" ng-click="moveup($index)" class="glyphicon glyphicon-arrow-up">subir</span></td>       <td><span ng-show="!$last" ng-click="movedown($index)" class="glyphicon glyphicon-arrow-down">bajar</span></td>     </tr>   </table>  </div> 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -