开发者

jQuery tablesorter plugin - disabling sorting on image within header

开发者 https://www.devze.com 2023-02-11 04:28 出处:网络
I have a large table (24 columns) that\'s using the tablesorter plugin, to save some space I\'m using vertical images to display the titles within the header.

I have a large table (24 columns) that's using the tablesorter plugin, to save some space I'm using vertical images to display the titles within the header.

I have a click event attached to a few selected images, this will open up a second table (via jQuery dialog) next to the header title that was clicked. The issue I开发者_C百科'm having is that when I click on the image the tablesorter is also sorting the column (which i don't want to happen) so I was trying to find a way to disable the sorting in some way, but only when I click on the title image.

Any help would be greatly appreciated!

HTML Code:

<table class="tablesorter" id="sales">
<thead>
 <tr>
  <th class="sales header" id="th_1"><img alt="" src="name.png" id="Name" onclick="openHeaderGeneric(this)"></th>
  <th class="sales header" id="th_2"><img alt="" src="date.png" id="Date" onclick="openHeaderGeneric(this)"></th>       
 </tr>
</thead>      
</table>

Here is the JS:

function openHeaderGeneric(element)
{   
// event triggered by clicking on img (title) not header (th)
var thId = $('#' + element.id).parent().attr('id');
var imageId = element.id;
var offset = $("th#" + thId).offset();
var top = offset.top;
var left = offset.left;
// get width of td cell (+8 for padding)
var tdWidth = thId.split('_');
tdWidth = tdWidth[1];
var width = $("td.col_" + tdWidth).width();
left = left + width + 8;

$.fx.speeds._default = 1000;

$("#" + imageId + "_wrapper").dialog( 
{
    autoOpen : false,
    show : "slide",
    hide : "slide",
    width : "auto",
    resizable : false,
    modal : false,
    position : [ left, top ]
});

if (!$("#" + imageId + "_wrapper").dialog("isOpen"))
{       
    $("#" + imageId + "_wrapper").dialog("open");
}
else if ($("#" + imageId + "_wrapper").dialog("isOpen"))
{       
    $("#" + imageId + "_wrapper").dialog("close");
}   

 } 


$('.header').unbind('click');

Add this before defining your click events. Or, if you only want to disable it for certain headers, use the IDs:

$('#th_1').unbind('click');
$('#th_2').unbind('click');

Or, if you want to be smarter about it:

jQuery.each($('.header img'), function(i, elem) {
  if ($(elem).data('events') !== undefined && $(elem).data('events').click !== undefined) {
    $(elem).parent().unbind('click');
  }
});

Should work I believe.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号