Ankündigung

Einklappen
Keine Ankündigung bisher.

[Erledigt] jquery tabelle sortieren und Position in input schreiben

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • [Erledigt] jquery tabelle sortieren und Position in input schreiben

    Hallo

    Ich möchte jedes mal, wenn eine Zeile in der Tabelle verschoben wird, dass die aktuelle Position in ein Input geschrieben wird. Jedoch bekomme ich das irgendwie nicht da rein. Aktuell wird das Input durch .html einfach gegen die Position ausgetauscht.

    Code:
    $( "table tbody" ).sortable({
            connectWith: ".table tbody",
            stop: function(event, ui) { 
                  $('table tbody tr').each(function(){
                  $(this).children('td:first-child').html($(this).index());
                                });
                                }
        });
    Code:
    <tr id="start_module_1">
                  <td class="left"><input type=text name="start_module_1[position]" size="1"/></td>
                  <td class="left"><input  type=text name="start_module_1[name]" size="15"/></td>
                  <td class="left">.</td>
                  <td class="left">.</td>
                  <td class="left">.</td>
                  <td class="left">.</td>             
                </tr>
                <tr>
                  <td class="left"><input class="id" type=text name="start_module_2[position]" size="1"/></td>
                  <td class="left"><input type=text name="start_module_2[name]" size="15"/></td>
                  <td class="left">.</td>
                  <td class="left">.</td>
                  <td class="left">.</td>
                  <td class="left">.</td>             
                </tr>

  • #2
    http://api.jquery.com/closest/
    http://api.jquery.com/index/

    ungetestet:
    PHP-Code:
    var $el = $( 'table tbody' ), // zu unspezifischer selektor
        
    $rows $el.children'tr' );
    $el.sortable({
        
    connectWith".table tbody",
        
    stop: function(eventui) {
            
    $el.find'input' ).each(function() {
                var 
    $this = $( this ),
                    
    $row $row.closest'tr' );
                    
                
    $this.val$rows.index$row ) );
            });
        }
    }); 
    Grüße

    Kommentar


    • #3
      Zitat von rudygotya Beitrag anzeigen
      http://api.jquery.com/closest/
      http://api.jquery.com/index/

      ungetestet:
      PHP-Code:
      var $el = $( 'table tbody' ), // zu unspezifischer selektor
          
      $rows $el.children'tr' );
      $el.sortable({
          
      connectWith".table tbody",
          
      stop: function(eventui) {
              
      $el.find'input' ).each(function() {
                  var 
      $this = $( this ),
                      
      $row $row.closest'tr' );
                      
                  
      $this.val$rows.index$row ) );
              });
          }
      }); 
      Grüße
      Danke für die Hilfe, aber das funktioniert nicht. Habe in allen Feldern dann eine 0 drin.

      Habe aber die Lösung gefunden
      Code:
      $( "table tbody" ).sortable({
              connectWith: ".table tbody",
              stop: function(event, ui) { 
                    $('table tbody tr').each(function(){
                    $(this).children('td:first-child').find('input').val($(this).index());
                                  });
                                  }
          });

      Kommentar

      Lädt...
      X