I have a table that represents a physical 12x8 grid. Each <td>
contains the text name (A1-H12) of the grid co-ordinate. I've added the jquery-ui selectable interaction to the table. I want users to be able to select an arbitrary set of grid co-ordinates. As well as selecting <td>
s I'd like the user to be able to select entire rows and/or columns by clicking on the row or column <th>
. Selection by <th>
is causing me some difficulty:
- How do I determine which
<td>
s are in the same column (or row) as the selected<th>
? - Which selectable event should I use to move the selection from a
th
to the correct set of<td>
s? stop, selected or selecting?
My jquery (which only allows me to look at the selected objects since I'm very unsure of how to do things):
$(function(){
$('#selectable').selectable({
filter:'td,th',
selected: function(event, ui){
console.log(event);
console.log(ui);
var s=$(this).find('.ui-selected');
console.log(s);
}
})
});
The table looks like this:
<table id='selectable'>
<tr>
<th> </th><!-- empty cell over row labels-->
<th class='colhead'>1</th>
...
<th class='colhead'>12</th>
</tr>
<tr>
<th class='rowhead'>A</th>
<td>A1</td>
...
<td>A12</td>
</tr>
...
<tr>
<th class='rowhead'>H</th>
<td>H1</td>
...
<td>H12</td>
</tr>
</table>