2010-12-22 6 views
7

Ich will mein 4. und 5. Feld durch die Informationen auf meinem INPUT attr VALUE sortierenjquery Tablesorter - Sortierfeld von <input value = "Wert">

Das ist mein html:

<table class=tablesorter width="764" border=1 cellpadding=0 cellspacing=0 id="objective3"> 
    <thead> 
    <tr> 
     <th bgcolor="#396FAE" class="divtopheader1">Strategy</th> 
     <th bgcolor="#396FAE" class="divtopheader1">Objective</th> 
     <th bgcolor="#396FAE" class="divtopheader1">Status</th> 
     <th bgcolor="#396FAE" class="divtopheader1">Target Date</th> 
     <th bgcolor="#396FAE" class="divtopheader1">Target</th> 
     <th bgcolor="#396FAE" class="divtopheader1">Actual</th> 
     <th bgcolor="#396FAE" class="divtopheader1">Cumulative</th> 
    </tr> 
    </thead> 
    <tbody> 
    <tr> 
     <td align="left" valign="top" class="tvertheadersm">Conservation</td> 
     <td width="27%" class="tvertheadersm">statutory authority.</td> 
     <td width="8%" align="center" valign="middle" class="tbody2"> 
      <input type=hidden value="1"> 
      <thewordIMGshouldgohere src="images/1" alt="Objective met" width=30 height=40 /> 
     </td> 
     <td width="11%" align=center class="tbody2"> 
      <input type=hidden value="092010">September<br>2010</td> 
      <td align=center class="tbody2">14 agencies</td> 
     <td align=center class="tbody2">14 agencies</td> 
     <td align=center class="tbody2">0 agencies</td> 
    </tr> 

Dies ist meine jquery, hier versuche ich nur für das 5. Feld, aber funktioniert nicht:

$(document).ready(function() { 
    // add parser through the tablesorter addParser method 
    $.tablesorter.addParser({ 
     // set a unique id 
     id: 'input', 
     is: function(s) { 
      // return false so this parser is not auto detected 
      return false; 
     }, 
     format: function(s) { 
      // format your data for normalization 
      return $("td input",$(s)).attr("value"); 
     }, 
     // set type, either numeric or text 
     type: 'numeric' 
    }); 

    $("table").tablesorter({ 
     // pass the headers argument and assing a object 
     headers: { 
      // assign the secound column (we start counting zero) 
      5: { 
       sorter:'input' 
      } 
     } 
    }); 
}); 

Jede Hilfe ist willkommen !!!

Frohe Feiertage :-)

Néstor

Antwort

6

"s" übergeben zu formatieren() Funktion ist eine Zeichenfolge mit Zellinhalt. Sie sollten Ihre Funktion umschreiben zu diesem aussehen wie

format: function(s) { 
    // format your data for normalization 
    return $($.trim(s)).val(); 
} 

Update: nahm einen genaueren Blick auf den Code und bei einem tablesorter.addParser

Es sieht aus wie Format() mit 3 Parametern aufgerufen wird, 3. ein Wesen die Zelle, auf die es angewendet wird. In Anbetracht dessen kann der Code wie folgt neu geschrieben werden:

format: function(s, table, cell) { 
    return $('input', cell).val(); 
} 

http://jsfiddle.net/RyCWM/1/

+0

Deutsch, Vielen Dank für Ihre schnelle Antwort. Das ist ein großartiges Werkzeug. Ich habe nichts davon gewusst. Danke für das Geschenk Santa German !!!! – user551799

+0

Danke SO, ich habe gerade über dieses Tool vor ein paar Tagen hier auf StackOverflow erfahren :) –

+0

Awesome, seit einer Weile jetzt gesucht. Vielen Dank. – KTamas

1

Wenn Sie den Inhalt des aktuellen Eingangs sortieren möchten, können Sie auf den Onchange Ereignisse der INPUT $ („table“) nennen sollte. triggern ("update"); Ein Parser muss sieht dann wie folgt aus:

$(document).ready(function() { 
     $.tablesorter.addParser({ 
      // add parser through the tablesorter addParser method$.tablesorter.addParser({ 
      // set a unique id 
      id:'input', 
      is:function (s) { 
       // return false so this parser is not auto detected 
       return false; 
      }, 
      format:function (s) { 
       // format your data for normalization 
       var obj=$($.trim(s)); 
       var id=obj[0].id; 
       var text=$("#"+id)[0].value; 
       return text; 
      }, 
      // set type, either numeric or text 
      type:'text' 
     }); 

     $("table").tablesorter({ 
      // pass the headers argument and assing a object 
      headers:{ 
       3:{ 
        sorter:'input' 
       } 
      } 
     }); 
    }); 
Verwandte Themen