DataTables是一個jQuery的表格插件。這是一個高度靈活的工具,依據的基礎逐步增強,這將增加先進的互動控制,支持任何HTML表格。
官方網站及其下載地址:http:/www.datatables.net
其主要特點如下:
1.自動分頁處理
2.即時表格數據過濾
3.數據排序以及數據類型自動檢測
4.自動處理列寬度
5.可通過CSS定制樣式
6.支持隱藏列
7.易用
8.可擴展性和靈活性
9.國際化
10.動態創建表格
11.免費的
html代碼:
1 <table id="result"> 2 <thead> 3 <th>姓名</th> 4 <th>組別</th> 5 <th>分單件數</th> 6 <th>當前待辦件數</th> 7 <th>總實收金額</th> 8 </thead> 9 </table>
js代碼:
1 function queryData(){ 2 var orgId=$("#orgId").val().trim(); 3 TableManaged = $('#result') 4 .dataTable( 5 { 6 "bDestroy" : true,// 銷毀 7 "bFilter" : false,// 不顯示搜索框 8 "bSort" : true, // 排序功能 9 "bAutoWidth" : true, 10 "sScrollX" : "100%", 11 "sScrollXInner" : "3600px", 12 "bPaginate" : true,// 分頁功能 13 "bInfo" : true,// 信息顯示 14 "sAjaxSource" : 'list.json',// 請求url 15 "sServerMethod" : "POST", 16 "bServerSide" : true, // 異步請求 17 "bProcessing" : true, 18 "fnServerParams" : function(aoData) { 19 aoData.push({ 20 "name" : "orgId",// 組織id 21 "value" : orgId 22 }, { 23 "name" : "userName",// 用戶名 24 "value" : $("#userName").val() 25 }); 26 }, 27 "aoColumns" : [ 28 { 29 "mData" : "userName",// 姓名 30 "bSortable" : false, 31 "sWidth" : "85px", 32 "sClass" : "txt-center", 33 "mRender" : function(data, type, full) {//data代表了該屬性的值,full表示整行對象(可以通過full.userId獲得該行的其他屬性值)
34 return '<a href="javascript:void(0)" class="userName" onclick="queryDetail(' 35 + full.userId+ ')" >' + data + '</a>'; 36 } 37 }, { 38 "mData" : "orgName",// 組別 39 "bSortable" : false, 40 "sWidth" : "85px", 41 "sClass" : "txt-center" 42 }, { 43 "mData" : "caseNum",// 分單件數 44 "bSortable" : false, 45 "sWidth" : "85px", 46 "sClass" : "txt-center" 47 }, { 48 "mData" : "caseTodoNum",// 當前待辦件數 49 "bSortable" : false, 50 "sWidth" : "90px", 51 "sClass" : "txt-center" 52 }, { 53 "mData" : "capitalAmount",// 總實收金額 54 "bSortable" : false, 55 "sWidth" : "100px", 56 "sClass" : "txt-center" 57 } ], 58 "aLengthMenu" : [ [ 10, 20, -1 ], [ 10, 20, "全部" ] ], 59 // set the initial value 60 "iDisplayLength" : 10, 61 "sPaginationType" : "bootstrap", 62 "oLanguage" : { 63 "sLengthMenu" : "每頁顯示 _MENU_ 條記錄 金額單位:元", 64 "sZeroRecords" : "抱歉, 沒有找到!", 65 "sInfo" : "從 _START_ 到 _END_ /共 _TOTAL_ 條數據", 66 "sInfoEmpty" : "顯示 0 至 0 共 0 項", 67 "oPaginate" : { 68 "sFirst":"首頁", 69 "sPrevious": "上一頁", 70 "sNext": "下一頁", 71 "sLast":"尾頁" 72 } 73 }, 74 // 回調函數 75 "fnDrawCallback" : function(oSettings) { 76 $("#query").removeAttr("disabled"); 77 $("#result_wrapper .row-fluid").css("margin-top", 78 "10px"); 79 var fsv = $( 80 "#result_length select[name='result_length']") 81 .val(); 82 if (fsv == "-1" || fsv == -1) { 83 $("#result_wrapper li").addClass("disabled"); 84 } 85 } 86 }); 87 }