javascript - Display first or on top those records in the table by a preferred creteria -


is there way display first records inside table has 'branch' of 'branch 1'? ideas, please? below snippet.

$(document).ready(function(){    $("#dtable").datatable( {              "pagingtype": "full_numbers",              "dom": 't<"clear">lfrtip',              "lengthmenu": [[10, 25, 50, -1],[10, 25, 50, "all"]],          });  });
<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>

you need use default sort of datatable more information can found here: https://datatables.net/examples/basic_init/table_sorting.html

basically need "order": [[ 1, "asc" ]]

demo:

$(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>


Comments