DataTables 1.9.4禁用特定行的排序

时间:2013-09-15 09:37:49

标签: javascript jquery datatables

我正在使用DataTables 1.9.4

<table border="0" cellpadding="0" cellspacing="0" class="display" id="example">
              <thead>
                <tr><th>Date</th><th>Discription</th><th>Amounts</th><th class="no-sort">Edit</th></tr>
              </thead>
              <tbody>
                <tr class="no-sort"><td>&nbsp;</td><td>Starting money</td><td>$500</td><td>edit</td></tr>
                <tr><td>2013-08-25</td><td>Payment out</td><td>-20</td><td>edit</td></tr>
                <tr><td>2013-08-26</td><td>a Given money</td><td>-80</td><td>edit</td></tr>
                <tr><td>2013-08-27</td><td>Fees taken</td><td>-100</td><td>edit</td></tr>
                <tr class="no-sort"><td>&nbsp;</td><td>Balance</td><td>$300</td><td>edit</td></tr>
              </tbody>
            </table>

我试图让第一行和最后一行不排序,编辑列不用这段代码排序

$(document).ready(function() {
            oTable = $('#example').dataTable({
                "bJQueryUI": true,
                "sPaginationType": "full_numbers",
                "iDisplayLength": 10,
                "aaSorting": [[ 0, "asc" ]],
                 "oLanguage": {
                  "sZeroRecords": "No records to display"
                 }
            });
            var $tr = $('#example tr.no-sort');
            var mySpecialRow = $tr.html();
            var opts = {};
        opts.fnDrawCallback = function(){
            $('#example tbody').prepend(mySpecialRow);
            };
            });

但它还没有工作,那些行正在排序,我搜索过每一个地方都可以帮助,谢谢

2 个答案:

答案 0 :(得分:0)

我认为你需要在thead中添加一行,在tfooter中添加一行,这样就不会对它有所帮助。

<table border="0" cellpadding="0" cellspacing="0" class="display" id="example">
<thead>
<tr>
<th>Date</th>
<th>Discription</th>
<th>Amounts</th>
<th>Edit</th>
</tr>
<tr class="no-sort">
<td>&nbsp;</td>
<td>Starting money</td>
<td>$500</td>
<td>edit</td>
</tr>
</thead>
<tbody>             
<tr>
<td>2013-08-25</td>
<td>Payment out</td>
<td>-20</td>
<td>edit</td>
</tr>
<tr>
<td>2013-08-26</td>
<td>a Given money</td>
<td>-80</td>
<td>edit</td>
</tr>
<tr>
<td>2013-08-27</td>
<td>Fees taken</td>
<td>-100</td>
<td>edit</td>
</tr>
</tbody>
<tfooter>
<tr class="no-sort">
<td>&nbsp;</td>
<td>Balance</td>
<td>$300</td>
<td>edit</td>
</tr>
</tfooter>
</table>

答案 1 :(得分:0)

你应该将最后一行放在“脚”中。 element(你使用过tfooter)。它会阻止排序