首页>>分页>>dataTables.js分页演示 支持排序,过滤(2019-05-02)

dataTables.js分页演示 支持排序,过滤

dataTables.js分页演示 支持排序,过滤
赞赏支持
立刻微信赞赏支持 关闭

 

XML/HTML Code
  1. <div class="container">  
  2.             <table id="employee-grid"  cellpadding="0" cellspacing="0" border="0" class="display" width="100%">  
  3.                     <thead>  
  4.                         <tr>  
  5.                             <th>演示名称</th>  
  6.                             <th>简介</th>  
  7.                             <th>点击次数</th>  
  8.                         </tr>  
  9.                     </thead>  
  10.                     <thead>  
  11.                         <tr>  
  12.                             <td><input type="text" data-column="0"  class="search-input-text"></td>  
  13.                             <th><input type="text" data-column="1"  class="search-input-text"></td>  
  14.                             <td>  
  15.                                 <select data-column="2"  class="search-input-select">  
  16.                                     <option value="">(Select a range)</option>  
  17.                                     <option value="1-100">1-100</option>  
  18.                                     <option value="101-1000">101-1000</option>  
  19.                                     <option value="1001-1000000">1001+</option>  
  20.                                 </select>  
  21.                             </td>  
  22.                         </tr>  
  23.                     </thead>  
  24.             </table>  
  25.         </div>  

 

JavaScript Code
  1. <script type="text/javascript" language="javascript" >  
  2.             $(document).ready(function() {  
  3.                 var dataTable = $('#employee-grid').DataTable( {  
  4.                     "processing"true,  
  5.                     "serverSide"true,  
  6.                     "ajax":{  
  7.                         url :"employee-grid-data.php"// json datasource  
  8.                         type: "post",  // method  , by default get  
  9.                         error: function(){  // error handling  
  10.                             $(".employee-grid-error").html("");  
  11.                             $("#employee-grid").append('<tbody class="employee-grid-error"><tr><th colspan="3">No data found in the server</th></tr></tbody>');  
  12.                             $("#employee-grid_processing").css("display","none");  
  13.                               
  14.                         }  
  15.                     }  
  16.                 } );  
  17.                 $("#employee-grid_filter").css("display","none");  // hiding global search box  
  18.                 $('.search-input-text').on( 'keyup click'function () {   // for text boxes  
  19.                     var i =$(this).attr('data-column');  // getting column index  
  20.                     var v =$(this).val();  // getting search input value  
  21.                     dataTable.columns(i).search(v).draw();  
  22.                 } );  
  23.                 $('.search-input-select').on( 'change'function () {   // for select box  
  24.                     var i =$(this).attr('data-column');    
  25.                     var v =$(this).val();    
  26.                     dataTable.columns(i).search(v).draw();  
  27.                 } );  
  28.                   
  29.                   
  30.                   
  31.             } );  
  32.         </script>  

 


原文地址:http://www.freejs.net/article_fenye_758.html