我有一个相当简单的jQuery数据表,它由几列组成,我有一列包含主题,截止日期和简要说明。
我想要做的是仅按截止日期对列进行排序,而忽略其余的。如果我只有日期,这样可以正常工作,但是一旦我添加了添加文本,它就不再正确排序。
以下是jQuery代码的片段:
$(document).ready(function() {
$('#casesDataTable').dataTable(
{
"sPaginationType": "full_numbers",
"aLengthMenu": [[25, 50, 100, -1], [25, 50, 100, "All"]],
"iDisplayLength": 100,
"aaSorting": [[1, "desc"]]
});
});
以下是没有CSS的HTML代码片段:
<tr>
<th id="subject" style="width:40%;">
Subject & Due Date
<span class="DataTables_sort_icon css_right ui-icon ui-icon-triangle-1-n"></span>
</th>
<th id="modified" style="width:10%;">
Last Modified
<span class="DataTables_sort_icon css_right ui-icon ui-icon-triangle-1-n"></span>
</th>
</tr>
<td class="center subject">
<span style="display: none;">9/26/2011</span>
<div class="padding">
tester 3
</div>
<div class="padding duedate">
<p>9/26/2011 - Mauris nulla mauris, ornare quis accumsan vitae, consectetur non sapien. In congue dui in sem cursus eleifend. Ut non suscipit augue. Praesent euismod auctor felis, eget pharetra justo euismod a. </p>
</div>
</td>
<td class="center sorting_1">
2/9/2011
</td>
<td class="center subject">
<span style="display: none;">4/30/2013</span>
<div class="padding">
tester 1
</div>
<div class="padding duedate">
<p>4/30/2013 - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque adipiscing rutrum lacinia. Donec ullamcorper ligula eu purus semper semper. Sed in est et nibh condimentum semper quis ultricies u...</p>
</div>
</td>
<td class="center sorting_1">
4/15/2013
</td>
<td class="center subject">
<span style="display: none;">5/16/2012</span>
<div class="padding">
tester 2
</div>
<div class="padding duedate">
<p>5/16/2012 - Nullam viverra, urna a tempus scelerisque, odio purus ultricies nibh, mollis pellentesque justo est quis augue. Quisque nec odio libero, tempus viverra leo.</p>
</div>
</td>
<td class="center sorting_1">
2/9/2012
</td>
<td class="center subject">
<span style="display: none;">5/16/2010</span>
<div class="padding">
tester 4
</div>
<div class="padding duedate">
<p>5/16/2010 - In vulputate rutrum elit nec mattis. Integer ullamcorper vestibulum sapien adipiscing gravida. Nullam quis ante diam, vel luctus elit. Quisque id adipiscing erat. ?</p>
</div>
</td>
<td class="center sorting_1">
2/9/2010
</td>
当我运行此脚本并按“上次修改”排序时,它工作正常,但如果我按“主题和截止日期”排序它会混淆,当我试图按截止日期排序时每个人都处于隐藏的范围内。
任何人都知道如何做到这一点,或者能看出我做错了什么?
答案 0 :(得分:4)
我遇到了类似的问题,并在前几天找到了解决方案。
对于任何列,您可以指定iDataSort参数,该参数指定要排序的备用列。您可以将此与您刚才拥有日期的额外列结合使用,但使用bVisible = false隐藏该列。
上的专栏帮助