1

我有一个相当简单的 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>

当我运行此脚本并按“上次修改时间”排序时,它工作正常,但如果我按“主题和截止日期”排序,它会搞砸,当我试图让它按隐藏的截止日期排序时跨越每个 .

任何人都知道如何做到这一点,或者可以看到我做错了什么?

4

1 回答 1

4

I had a similar problem and found the solution the other day.

For any column, you can specify an iDataSort parameter which specifies the alternative column to sort by. You can combine this with an extra column that you just have the date in, but hide that column using bVisible = false.

See the column help at http://datatables.net/usage/columns

于 2013-04-15T16:57:30.617 回答