jQuery排序表列
我正在尝试使用jQuery对表进行排序。在我的表中,有两列我需要排序,如果排序,它必须隐藏行 “我的表”在创建时如下所示:jQuery排序表列,jquery,html,sorting,Jquery,Html,Sorting,我正在尝试使用jQuery对表进行排序。在我的表中,有两列我需要排序,如果排序,它必须隐藏行 “我的表”在创建时如下所示: <table id="vermogen_gewicht" class="table table-hover vermogen_gewicht"> <thead></thead> <tbody> <tr class="uitvoering_1 "> <td class="radiobut
<table id="vermogen_gewicht" class="table table-hover vermogen_gewicht">
<thead></thead>
<tbody>
<tr class="uitvoering_1 ">
<td class="radiobutton">
<td id="gewicht" class="gewicht">2000</td>
<td id="type" class="type">L1H1</td>
</tr>
</tbody>
这样做的目的是在
元素中选择一个选项。然后隐藏与选定选项值不同的元素。这就像预期的那样工作,但是在我根据“类型”排序之后,我现在想要根据“gewicht”排序;我使用此代码执行此操作:
$('#filtertype1').change(function(){
var criteria1 = $(this).val();
if(criteria1 == 'ALL'){
$('.vermogen_gewicht tr').show();
return;
}
$('.gewicht').each(function(i,option){
if($(this).html() == criteria1 && $('.type').html() == criteria){
$(this).parent().show();
}else {
$(this).parent().hide();
}
});
});
但这不起作用,例如,我选择类型1,它显示包含类型1的每一行,并隐藏其他行。然后,当我在元素“gewicht”上选择2000时,它应该显示类型为1和gewicht 2000的所有内容,但现在我这样做时,它只是隐藏了所有内容
即使我改变了这一点:
if($(this.html()==criteria1&&$('.type').html()==criteria){
对此if($(this).html()==criteria1{
它将正常工作,如果我选择type=1 gewicht=2000,它将正确显示并隐藏其他行,但当我将“gewicht”更改为2100时,它也将显示type 2,因此它将覆盖第一个排序。这可能不会发生。我如何解决此问题?“d如果排序,它必须隐藏该行。”-因此,一旦你排序,你就隐藏了所有的行?没有意义,请澄清显示一些表标记和一些示例预排序和后排序-显示一行表会使其不那么清晰类“radiobutton”没有内容或结束标记我想你说的是筛选(隐藏那些不符合条件的行)而不是排序(以不同的顺序排列行,但保持所有行都可见)
$('#filtertype1').change(function(){
var criteria1 = $(this).val();
if(criteria1 == 'ALL'){
$('.vermogen_gewicht tr').show();
return;
}
$('.gewicht').each(function(i,option){
if($(this).html() == criteria1 && $('.type').html() == criteria){
$(this).parent().show();
}else {
$(this).parent().hide();
}
});
});