Gayane
Gayane

Reputation: 647

How to select row in table jquery?

I have a table with following columns

|type |status |owner |host | 

I need to select the rows which contain for example (type1 or ... or type20) && (status1 or ... status5) && (owner1 or .. or owner4) etc.

I know that if I need to have the rows which contains type1&&owner2&&staus1 I can do the following

$(table tr:contains('type1'):contains('owner2'):contains('status1'));

Can someone explain how to handle this?

Upvotes: 0

Views: 53

Answers (1)

Alnitak
Alnitak

Reputation: 340055

I would use something like this:

var $rows =  $('table tr').filter(function() {
    return ...;
});

where ... is the predicate for matching the cells you want.

Don't forget that you can use this.cells[n] to directly and efficiently access the individual cells, and .textContent (or .innerText) to read the cells' values.

So, part of your predicate could be:

this.cells[0].textContent.match(/^type([1-9]|1[0-9]|20)$/)

Upvotes: 2

Related Questions