Unexpected cell-selector behavior
Unexpected cell-selector behavior
When using the form of cell( row-selector
, cell-selector
) with a classname I expected the cell()
API to search the row-selector
results for the class. However it seems to only find the class if its defined in the thead
. Test Case:
https://live.datatables.net/kosukanu/1/edit
console.log( 'Class name defined in thead th', table.cells( 0, '.name').count() );
console.log( table.cells( 0, '.name').data() );
console.log( 'Class position defined in tbody td', table.cells( 0, '.position').count() );
console.log( table.cells( 0, '.position').data() );
<thead>
<tr>
<th class="name">Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
....
<tr>
<td>Tiger Nixon</td>
<td class="position">System Architect</td>
<td>Edinburgh</td>
<td>61</td>
<td>2011/04/25</td>
<td>$3,120</td>
</tr>
I expected the cell with class position
to be found not the cell where the th
has the class name
.
The [jQuery selector` docs state this:
jQuery instance can be given as a cell selector, with any nodes which are selected by jQuery and match those available in the table's
tbody
selected.
Kevin
Replies
Also using
table.cells( 0, 'td')
doesn't seem to work buttable.cells( 0, 'th')
does work. Update test case:https://live.datatables.net/bofederi/1/edit
Using a jQuery object like this does work:
Kevin
In this form it is is
.cells( rowSelector, columnSelector )
. Or in other words, from row index 0, find columns which have aname
class. The column class selector operates on the header (which also explains whyth
works buttd
doesn't).If you want to select a cell based on the cell's own class you need to use the cell selector overload:
If you want a
position
class cell from a specific row:Does that make sense?
Allan
Guess I need to look closer at the docs. As you said its
.cells( rowSelector, columnSelector )
not.cells( rowSelector, cellSelector )
Kevin