Javascript 带有分页和AJAX的Tablesorter错误
我在我的表中使用JS tablesorter,它使用append方法填充AJAX; 因此,当我在第1页时,表排序器工作得很好。但当我在第2页或+,一个错误出现,因为它是排序的每一页行之前,我在 这是我的AJAX,用于填充表:Javascript 带有分页和AJAX的Tablesorter错误,javascript,jquery,html,ajax,tablesorter,Javascript,Jquery,Html,Ajax,Tablesorter,我在我的表中使用JS tablesorter,它使用append方法填充AJAX; 因此,当我在第1页时,表排序器工作得很好。但当我在第2页或+,一个错误出现,因为它是排序的每一页行之前,我在 这是我的AJAX,用于填充表: function getData(page){ totalclientes =0; totalclientes = 0; var url = "../getters/getAtivosPainel.php?Lojas&offset="+p
function getData(page){
totalclientes =0;
totalclientes = 0;
var url = "../getters/getAtivosPainel.php?Lojas&offset="+page;
var data = "";
$.get(url, function(response){
serverResponse = response;
console.log(response);
for(i in response.content){
data +='\
<tr>\
<td>'+response.content[i].LojaNome+'</td>\
<td>'+response.content[i].LojaBairro+'</td>\
<td>'+response.content[i].LojaTelefone1+'</td>\
<td>'+LojaStatus+'</td>\
<td>'+response.content[i].PlanoNome+'</td>\
<td>'+response.content[i].Diferenca+'</td>\
</tr>';
}
$('#corpotabela').empty();
$('#corpotabela').append(data);
$('#qtd').empty();
$('#qtd').append(response.count);
$('table').tablesorter();
var width = new Array();
$(".table-body tr:eq(0)").find('td').each(function (position){
width[position] = $(this).outerWidth();
});
$(".table-header tr").find('th').each(function (position){
$(this).css("width", width[position]+2);
});
});
}
函数getData(第页){
客户总数=0;
客户总数=0;
var url=“../getters/getAtivosPainel.php?Lojas&offset=“+page;
var数据=”;
$.get(url、函数(响应){
服务器响应=响应;
控制台日志(响应);
对于(i在response.content中){
数据+='\
\
“+response.content[i].LojaNome+”\
“+response.content[i].LojaBairro+”\
“+response.content[i].LojaTelefone1+”\
“+LojaStatus+”\
'+response.content[i].PlanoNome+'\
“+response.content[i].Diferenca+”\
';
}
$('#corpotabela').empty();
$(#corpotabela')。追加(数据);
$('#qtd').empty();
$('#qtd').append(response.count);
$('table').tablesorter();
var width=新数组();
$(“.table body tr:eq(0)”).find('td')。每个(函数(位置){
宽度[位置]=$(此).outerWidth();
});
$(“.table header tr”).find('th').each(函数(位置){
$(this.css(“宽度”,宽度[位置]+2);
});
});
}
这张是我的桌子
<table class="table table-bordered table-hover" id="table">
<thead style="border: 1px solid #ddd;" >
<tr style="cursor: pointer;">
<th>Nome</th>
<th>Bairro</th>
<th>Telefone</th>
<th>Status</th>
<th>Plano</th>
<th>Dias para fim do plano</th>
<th>Ações</th>
</tr>
</thead>
<tbody id="corpotabela">
</tbody>
</table>
</div>
<div style="text-align:left; margin-top: -25px;">
<nav id="navi">
<ul class="pagination">
<li>
<a href="#" aria-label="Previous">
<span aria-hidden="true">«</span>
</a>
</li>
<?php
$j = 0;
$k=1;
for($i =$cnt; $i > 0; $i--) {
echo '<li><a id="datas" href="javascript:getData('.$j.')">'.$k.'</a></li>';
$j = $j+30;
$k++;
}
?>
<li>
<a href="#" aria-label="Next">
<span aria-hidden="true">»</span>
</a>
</li>
</ul>
</nav>
</div>
诺姆
拜罗
电传
地位
普拉诺
帕拉菲姆公寓
Ações
-
-
您能给我一个帮助吗?您应该只初始化一次tablesorter
$(function(){
$('table').tablesorter();
var getData = {
// add rows here
$('table').trigger('update');
};
});
添加新数据时,使用$('table')。触发器('update')
向tablesorter发送内容已更改的信号