Jquery set tr with empty td lower than with text in td
- by PavelBY
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();
});