I’m trying to have a table with sortable rows – but also one of these rows needs a dropdown in it.
The issue is, when clicking the dropdown – the click event for the table header is firing causing things to happen that shouldn’t.
I found this :
http://www.velocityreviews.com/forums/t367867-table-row-background-onclick.html
But I thought – there must be a more elegant solution?
Any takers?
Sorry – I forgot examples!
<th onclick="SortBy(event,'ctl00$mainContent$hiddenPBButton','descending','1')" class="tableDataHeader">
<select id="groupby1"` onchange="performPostBackfromDrop(event,this,'ctl00$mainContent$hiddenPBButton');"><option value="Enquiry Type">Enquiry Type</option>
<option value="Location">Location</option>
<option value="Source">Source</option>
<option selected="" value="User">User</option>
</select>
</th>
JS
As you can see – the JS is pretty generic – but I’ve included it for clarity
function SortBy(e, PBID,direction, field)
{
performPostBackfromSort(PBID,direction,field);
}
function performPostBackfromSort(PBID, direction, field)
{
__doPostBack(PBID, "sort"+"-"+direction+"-"+field);
}
function performPostBackfromDrop(e,sender, PBID)
{
var value = getDropDownSelectedValue(sender);
__doPostBack(PBID, $j(sender).attr('id')+"-"+value);
}
Add an onclick event to the select and stop propagation (FireFox) or stop bubbling (IE).
Here is the sample code I used.