views:

271

answers:

2

I need to select and act on a table element with JQuery, but only when it contains at least one row with more than one column. The following selector works, but only gets me part way:

$('#my_table_is:has(tbody tr)').doSomething();

Variations I have tried with no success are:

$('#my_table_id:has(tbody > tr > td:eq(1))').doSomething();
$('#my_table_id:has(tbody tr:nth-child(1))').doSomething();
$('#my_table_id:has(td:eq(1))').doSomething();

What combination of selector and filter will make this work?

BTW, the reason I need this is that tablesorter with a multi-column sortList, will apparently blow up when there is only 1 column in the table output.

A: 

how about just a good ole check?

if (1 < $('#tbl thead th').size()) ...
neouser99
@neouser99 Thanks, that did the trick. FWIW, I needed a row within the tbody, so my solution was: if (1 < $('#tbl_id tbody tr td').size()) {...
aponzani
A: 

Would it not be easier to actually fix the tablesorter instead of hacking around? (I assume you mean http://tablesorter.com/).

van
The other issue with tablesorter is its recognition of the column datatype by the first row only.
van
I'm pretty happy with tablesorter so far. It def. beats returning to the DB and writing dynamic SQL to change an ORDER BY. And I prefer not to hack up someone else's library because I don't want to re-hack it whenever he/she releases a new version
aponzani
Good point, even though I am sure the author would be happy to incorporate your fix.
van