2010-12-22 12 views
7

quiero ordenar mi cuarto y quinto campo de la información de mi entrada de valor attrjQuery Tablesorter - campo de clasificación por <input value = "valor">

Ésta es mi 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> 

Este es mi jquery, aquí estoy intentando solo para el 5to campo pero no está funcionando:

$(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' 
      } 
     } 
    }); 
}); 

Cualquier ayuda es bienvenida !!!

fiestas :-)

Néstor

Respuesta

6

"s" pasó a formatear() es una cadena con contenido de células. Usted debe reescribir su función para tener este aspecto

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

Actualización: tomó una mirada más cercana a su código y en una tablesorter.addParser

Parece formato() se llama con 3 parámetros, siendo uno tercero la celda en la que se aplica. Teniendo en cuenta esto, el código se puede escribir así:

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

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

+0

Alemán, Gracias por su pronta respuesta. Esa es una herramienta increíble. No sabía sobre eso. Gracias por el presente Santa German !!!! – user551799

+0

Gracias SO, acabo de enterarme de esta herramienta hace un par de días aquí en StackOverflow :) –

+0

Impresionante, estado buscando esto desde hace un tiempo. Gracias. – KTamas

1

Si desea ordenar el contenido de la entrada de corriente, debe llamar en los eventos onChange INPUT $ ("mesa"). disparador ("actualización"); Un analizador debe tener el siguiente aspecto:

$(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' 
       } 
      } 
     }); 
    }); 
Cuestiones relacionadas