我正在尝试使用此page中的tablesorter插件。这是一个非常简单的插件,可以在客户端进行排序。
这是我的转发器:
<asp:Repeater ID="RepeaterChangeLog" runat="server" >
<HeaderTemplate>
<table id="ChangeLogTable" class="table tablesorter table-bordered">
<thead>
<tr>
<th>Date de correction</th>
<th>Correcteur</th>
<th>BugID</th>
<th>Catégorie</th>
<th>Module</th>
<th>Description de la correction</th>
<th>Impact</th>
<th>Rapporté par</th>
<th>Demandé par</th>
</tr>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tbody>
<tr>
<td width="125px"> <%# DataBinder.Eval(Container.DataItem, "ChangeLogDate")%></a></td>
<td width="100px"> <%# DataBinder.Eval(Container.DataItem, "FixedBy")%> </td>
<td width="75px"> <%# DataBinder.Eval(Container.DataItem, "BugID")%> </td>
<td width="100px"> <%# DataBinder.Eval(Container.DataItem, "Category")%> </td>
<td width="100px"> <%# DataBinder.Eval(Container.DataItem, "Module")%> <%# DataBinder.Eval(Container.DataItem, "AdditionalModule")%></td>
<td width="300px"> <%# DataBinder.Eval(Container.DataItem, "Description")%> </td>
<td width="300px"> <%# DataBinder.Eval(Container.DataItem, "Impact")%> </td>
<td width="100px"> <%# DataBinder.Eval(Container.DataItem, "ReportedBy")%> </td>
<td width="100px"> <%# DataBinder.Eval(Container.DataItem, "AskedBy")%> </td>
</tr>
</tbody>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
以下是我如何调用tablesorter
$(document).ready(function () {
$("#ChangeLogTable").tablesorter();
});
结果很奇怪。我可以看到应用的CSS,当我点击标题时,向上和向下箭头正在改变,但排序本身不起作用。我在相同的页面中尝试了一个非常简单的here表格,该表格工作正常。我可以在2中看到的唯一区别是,一个是使用转发器生成的,另一个是纯HTML。在我看来,它应该没有什么区别,因为结果是相同的HTML,但也许微软在标题中放置了一些秘密和隐藏的代码,使插件失败。
我希望有人可以帮我解决这个问题!谢谢!
答案 0 :(得分:1)
我发现了问题,我不敢相信我第一次没有看到它,但是......这是星期五!
该插件正在使用“新”thead和tbody,我不太习惯。当我创建我的转发器时,我只是将thead放在HeaderTemplate中,将tbody放在ItemTemplate中。但是我忘记的是ItemTemplate在每一行都不断重复,所以我的表有多个tbody。这不行,插件不适用于此。换句话说,这是糟糕的HTML。
所以这里是好的转发器,将tbody放在正确的位置:
<asp:Repeater ID="RepeaterChangeLog" runat="server" >
<HeaderTemplate>
<table id="ChangeLogTable" class="table tablesorter table-bordered">
<thead>
<tr>
<th>Date de correction</th>
<th>Correcteur</th>
<th>BugID</th>
<th>Catégorie</th>
<th>Module</th>
<th>Description de la correction</th>
<th>Impact</th>
<th>Rapporté par</th>
<th>Demandé par</th>
</tr>
</thead>
<tbody>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td width="125px"> <%# DataBinder.Eval(Container.DataItem, "ChangeLogDate")%></a></td>
<td width="100px"> <%# DataBinder.Eval(Container.DataItem, "FixedBy")%></td>
<td width="75px"><a href="http://adobs.aquadata.com/edit_bug.aspx?id=<%# DataBinder.Eval(Container.DataItem, "BugID")%>"><%# DataBinder.Eval(Container.DataItem, "BugID")%></a></td>
<td width="100px"> <%# DataBinder.Eval(Container.DataItem, "Category")%></td>
<td width="100px"> <%# DataBinder.Eval(Container.DataItem, "Module")%> <%# DataBinder.Eval(Container.DataItem, "AdditionalModule")%></td>
<td width="300px"> <%# DataBinder.Eval(Container.DataItem, "Description")%></td>
<td width="300px"> <%# DataBinder.Eval(Container.DataItem, "Impact")%></td>
<td width="100px"> <%# DataBinder.Eval(Container.DataItem, "ReportedBy")%></td>
<td width="100px"> <%# DataBinder.Eval(Container.DataItem, "AskedBy")%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</tbody>
</table>
</FooterTemplate>
</asp:Repeater>
答案 1 :(得分:0)
我遇到的一个问题是我引用了转发器Id而不是其中的表的ID。