JQuery hide all table rows that contain a hidden field corresponding to a value

Although I have no doubt that this was answered, I cannot find an excellent answer to my question.

I have a table for which I would like to filter rows based on whether they contain a hidden field corresponding to the value.

I understand that this technique tends to "show all rows", "filter a set", "show / hide that filtered set"

I have the following jquery, but I am wise with a filter, and my filtered set seems to always contain no elements.

My table is regular

<table>
<tr><td>header></td><td>&nbsp;</tr>
<tr>
<td>a visible cell</td><td><input type='hidden' id='big-asp.net-id' value='what-im-filtering-on' />
</td>
</tr>
</table>

My goal is to be able to match tr, whose descendants contain hidden input containing either true or false.

( ), .

function OnFilterChanged(e){
    //debugger;
    var checkedVal = $("#filters input[type='radio']:checked").val();
    var allRows = $("#match-grid-container .tabular-data tr");
    if(checkedVal=="all"){        
         allRows.show();
    }
    else if(checkedVal=="matched"){
         allRows.show();
         allRows.filter(function(){$(this).find("input[type='hidden'][id~='IsAutoMatchHiddenField']")}).hide();

    }
    else if(checkedVal=="unmatched"){

    }
}

? $(this), , ?

,

, , . , true/false . , asp.net INamingContainer

allRows.show();
allRows.filter(function(){
            return $(this).find(
               "input[type='hidden'][id$='IsAutoMatchHiddenField']").val() == "False";
         }).hide();
+3
3
$('#mySelector :hidden').filter(
    function (index)
    {
        return $(this).find('.repeatedObject').val() == 'someValue';
    }
).hide();

filter() , , . API (http://api.jquery.com/filter/) .

, val(), html(), text() first . , each for.

+3

.

  • find .
  • ? ? [id~='IsAutoMatchHiddenField']
  • [attribute~=value], , whitespace, : [value~='foo'] value="foo-bar", value="foo bar".

.

// Chain your functions, the beauty of jQuery.
allRows.show()
   .filter(function(index){
      // function needs to return a boolean.
      return $(this)
         .find("input[type='hidden'][id~='IsAutoMatchHiddenField']")
         .val() == 'valuetocheck';
   });
+2

I think you need to return a boolean or equivalent value from a function filter. What about:

allrows.filter(function() {
    return $(this).find(':hidden').length;
}).hide();

Or:

$('tr :hidden').closest('tr').hide();
+1
source

Source: https://habr.com/ru/post/1741347/


All Articles