Div strangely shown at the top with Tablesorter
I'm using http://tablesorter.com/docs/ to try to sort a table. It works with a cosmetic issue that is not so much disturbing. The "zebra" doesn't activate until you really try to order the table. Isn't annoying at all but I couldn't find why this happens.
My really problem is that I'm trying to use also the pager plugin. The pager div appears at the top of the page. It may be caused (both problems) because I have the table inside a prior hidden tab the first time it appears. The content is loaded from a PHP file via AJAX and, when loaded, depending on the data, I could active tabs and tablesorter (or not). If I do that, I do with this lines of code:
(".tab_content").hide();
$("ul.tabs li:first").addClass("active").show();
$(".tab_content:first").show();
$("#calls").tablesorter({widthFixed: true, widgets: ['zebra']}).tablesorterPager({container: $("#pager")});
The "pager" div is inside the tab, just below the target table.
As @mu is to shoort stated pager needs to know where the table is.
Tabs are loaded with
<ul class="tabs">
<li><a href="#cont-standard-report">Standard</a></li>
<li><a href="#cont-extensions-report">Extensions</a></li>
<li><a id="calls" href="#cont-calling-report">Callings</a></li>
</ul>
So, I tried with the proposed function but it even doesn't call it when clicking the tab.
$("#cont-calling-report").one('click', function() {
alert ("Test");
$("#calls").tablesorter({widthFixed: true, widgets: ['zebra']})
.tablesorterPager({container: $("#pager")});
});
This is what happens. No click needed.
Managed to solve with this
Managed to solve it with this:
if (activeTab == '#cont-callings-report' && !tablesorter){
$("#calls").tablesorter({widthFixed: true, widgets: ['zebra']}).tablesorterPager({con开发者_运维问答tainer: $("#pager")});
tablesorter = 1;
}
Inside the tab function.
The pager plugin probably needs to know where the table is and how big the table is before it can properly position itself. When your tab is hidden, the table inside it doesn't have a useful position so the pager probably ends up with zeros for the position it needs and the result is the pager at the top of the page. The easiest solution would be to bind tablesorter
when the tab is clicked:
$(selector_for_the_tab_with_the_table).one('click', function() {
$("#calls")
.tablesorter({widthFixed: true, widgets: ['zebra']})
.tablesorterPager({container: $("#pager")});
});
You only need to bind it once so use .one
:
This method is identical to
.bind()
, except that the handler is unbound after its first invocation.
精彩评论