update input with jQuery

0

In each row of the table I have an input, I need to change the value of the input with the value of the line position. How can I do this?

$(document).ready(function () {
        $('tbody').sortable({
            axis: 'y',
            containment: 'parent',
            change: function(){ 
console.log("change"); 
              $.each($(".tab_dados tbody>tr"), function(indice, obj){
                 $(this).find($("td>input[type=text]")).val(indice + 1);
              });
        }
        });
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.js"></script>
<table class="tab_dados">
  <thead>
  <tr>
    <th style="width: 30px;"></th>
    <th>CÓDIGO</th>
    <th>NOME</th>
    <th>input</th>
  </tr>
  </thead>
  <tbody>
  <tr>
    <td>&nbsp;</td>
    <td>25</td>
    <td>HUGO</td>
    <td><input type="text" name="id25" value="1"></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>26</td>
    <td>bruno</td>
    <td><input type="text" name="id26" value="2"></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>27</td>
    <td>rafael</td>
    <td><input type="text" name="id27" value="3"></td>
  </tr>
</tbody>
</table>
    
asked by anonymous 08.05.2017 / 18:59

1 answer

3
   $(document).ready(function () {
        $('tbody').sortable({
            axis: 'y',
            containment: 'parent',
            animation: 200,
            stop: function(){  
                  $.each($(".tab_dados tbody>tr"), function(indice, obj){
                     $(this).find($("input[type=text]")).val(indice + 1);
                  });
            }
        });
    });

At event: stop sortable can check all rows.

Take a look at the documentation for what you'll need from now on: Sortable

    
08.05.2017 / 19:23