Jquery set tr with empty td lower than with text in td

Posted by PavelBY on Stack Overflow See other posts from Stack Overflow or by PavelBY
Published on 2012-11-14T21:11:40Z Indexed on 2012/11/14 23:00 UTC
Read the original article Hit count: 321

Filed under:
|
|

I have html, and jquery for sorting my table (also there is non-standart sorting (with multi-tbody)).

My code could be found here: http://jsfiddle.net/GuRxj/

As you can see there, td with prices (on russian ????) are sorted ascending (but tech-as not!? why? (it a question too))... But as you see, i need to send this tr's with prices to top of this tbody (now there are in the bottom), while empty-price-tr send to bottom... How to do this?

part of js:

$('.prcol').click(function(e) {
      var $sort = this;
      var $table = $('#articles-table');
      var $rows = $('tbody.analogs_art > tr',$table);
      $rows.sort(function(a, b){
          var keyA = $('td:eq(3)',a).text();
          var keyB = $('td:eq(3)',b).text();
            if (keyA.length > 0 && keyB.length > 0)
            {
              if($($sort).hasClass('asc')){
                  console.log("bbb");
                  return (keyA > keyB) ? 1 : 0;
              } else {
                console.log(keyA+"-"+keyB);
                  return (keyA > keyB) ? 1 : 0;
              }
            }
      });
      $.each($rows, function(index, row){
        //console.log(row);
        $table.append(row);
        //$("table.123").append(row);
      });
      e.preventDefault();
    });

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery