首选或首选显示表格中的那些记录

时间:2016-01-29 04:05:57

标签: javascript jquery datatables datatables-1.10

有没有办法可以首先在表格中显示那些有'分支的记录? '分支1'?任何想法,请帮忙吗?下面是我的片段。



$(document).ready(function(){
  $("#dtable").DataTable( {
            "pagingType": "full_numbers",
            "dom": 'T<"clear">lfrtip',
            "lengthMenu": [[10, 25, 50, -1],[10, 25, 50, "All"]],
        });
});
&#13;
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://cdn.datatables.net/1.10.10/css/jquery.dataTables.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.10.10/js/jquery.dataTables.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

<table id="dtable" class="table table-hover">
  <thead>
    <tr>
      <th>NAME</th>
      <th>BRANCH</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>NAME 1</td><td>BRANCH 1</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 1</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 1</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 1</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 1</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 1</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 1</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 2</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 1</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 2</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 2</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 3</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 3</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 3</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 3</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 1</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 1</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 1</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 1</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 1</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 1</td>
    </tr>
  </tbody>
</table>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:2)

您需要使用默认的数据表类型,可在此处找到更多信息: https://datatables.net/examples/basic_init/table_sorting.html

基本上你只需要"order": [[ 1, "asc" ]]

演示:

$(document).ready(function(){
  $("#dtable").DataTable( {
            "pagingType": "full_numbers",
            "dom": 'T<"clear">lfrtip',
            "lengthMenu": [[10, 25, 50, -1],[10, 25, 50, "All"]],
      "order": [[ 1, "asc" ]]
        });
});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://cdn.datatables.net/1.10.10/css/jquery.dataTables.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.10.10/js/jquery.dataTables.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

<table id="dtable" class="table table-hover">
  <thead>
    <tr>
      <th>NAME</th>
      <th>BRANCH</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>NAME 1</td><td>BRANCH 1</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 1</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 1</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 1</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 1</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 1</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 1</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 2</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 1</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 2</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 2</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 3</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 3</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 3</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 3</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 1</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 1</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 1</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 1</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 1</td>
    </tr>
    <tr>
      <td>NAME 1</td><td>BRANCH 1</td>
    </tr>
  </tbody>
</table>