<address id="ttjl9"></address>

      <noframes id="ttjl9"><address id="ttjl9"><nobr id="ttjl9"></nobr></address>
      <form id="ttjl9"></form>
        <em id="ttjl9"><span id="ttjl9"></span></em>
        <address id="ttjl9"></address>

          <noframes id="ttjl9"><form id="ttjl9"></form>

          JqueryTable的使用

          2021-7-7    前端達人

          1.目的

          用漂亮的前端表格直觀顯示數據

           

          2. JqueryTable簡介

          JqueryTable官網

          表格顯示

           

          3.用法

          1.初始化html頁面

          設置一個table

          
          
          1. <table id="table_id" class="display">
          2. <thead>
          3. <tr>
          4. <th>Column 1</th>
          5. <th>Column 2</th>
          6. </tr>
          7. </thead>
          8. <tbody>
          9. <tr>
          10. <td>Row 1 Data 1</td>
          11. <td>Row 1 Data 2</td>
          12. </tr>
          13. <tr>
          14. <td>Row 2 Data 1</td>
          15. <td>Row 2 Data 2</td>
          16. </tr>
          17. </tbody>
          18. </table>

           

          2.引入靜態資源

          這個是JqueryTable必要的靜態資源

          
          
          1. <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.css">
          2. <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.js"></script>

          如果你使用了js, 那么還需要引入jquery.js

           

          3.初始化表格

          
          
          1. $(document).ready( function () {
          2. $('#table_id').DataTable();
          3. } );

          3.實例

           

          1. html頁面

          
          
          1. <table id="tbl_grantedCoach" class="table table-striped table-bordered nowrap" style="table-layout:fixed; text-align: center;">
          2. <thead>
          3. <tr>
          4. <th width="10%">用戶名</th>
          5. <th width="10%">姓名</th>
          6. <th width="8%">性別</th>
          7. <th width="10%">手機號</th>
          8. <th width="5%">工作年限</th>
          9. <th width="12%">教員類型</th>
          10. <th width="15%">角色</th>
          11. <th width="10%">備注</th>
          12. <th width="12%">操作</th>
          13. </tr>
          14. </thead>
          15. </table>

           

          2.js代碼

          ajax 發送請求, 接受表格數據,再填寫進去

          
          
          1. initGrantedCoachGrid:function(){
          2. selectedUserId =[];
          3. if(grantedCoachGrid){
          4. grantedCoachGrid.ajax.url(
          5. "course/getGrantedCoachByFolder?json&folderId="
          6. + selectNodeId + "").load();
          7. } else {
          8. grantedCoachGrid = $('#tbl_grantedCoach')
          9. .DataTable(
          10. {
          11. "lengthMenu" : [ [ 10, 20, 30 ],
          12. [ 10, 20, 30 ] // change per page
          13. // values here
          14. ],
          15. "ordering":false,
          16. "retrieve":true ,
          17. "bDestory" :true,
          18. "pageLength": 10,
          19. "bAutoWidth" : false,
          20. "ajax" : {
          21. "url" : "course/getGrantedCoachByFolder?json&folderId="
          22. + selectNodeId + "",
          23. "type" : "get",
          24. "cache" : false,
          25. "contentType" : "application/json; charset=utf-8",
          26. "dataSrc" : ""
          27. },
          28. "rowCallback" : function(row, data) {
          29. selectedUserId.push(data.userId);
          30. },
          31. "aoColumnDefs" : [ {
          32. sDefaultContent : '',
          33. aTargets : [ '_all' ]
          34. } ],
          35. // 填入列數據
          36. "columns" : [
          37. {
          38. "data" : "loginName"
          39. },
          40. {
          41. "data" : "userFullName"
          42. },
          43. {
          44. "data" : "gender",
          45. "mRender" : function(data,
          46. type, full) {
          47. if (data == "M") {
          48. return "男";
          49. } else if (data == "F") {
          50. return "女";
          51. }
          52. }
          53. },
          54. {
          55. "data" : "mobilePhone"
          56. },
          57. {
          58. "data" : "workYear"
          59. },
          60. { "data": "coachType" , "mRender":function(data,type,full){
          61. if(data=="0")
          62. {
          63. data="理論培訓";
          64. }else if(data=="1"){
          65. data="實習培訓";
          66. }else{
          67. data="理論培訓+實習培訓";
          68. }
          69. return data;
          70. }},
          71. {
          72. "data" :function( row, type, val, meta ){
          73. return row.userRoles[0].roleName;
          74. }
          75. },
          76. {
          77. "data" : "remark"
          78. },
          79. {
          80. "data" : null,
          81. "mRender" : function(data,
          82. type, full) {
          83. return "";
          84. }
          85. }
          86. ],
          87. "oLanguage" : {
          88. "sProcessing" : "正在加載中......",
          89. "sLengthMenu" : "每頁顯示_MENU_條記錄",
          90. "sZeroRecords" : "對不起,查詢不到相關數據!",
          91. "sEmptyTable" : "無數據存在!",
          92. "sInfo" : "當前顯示_START_到_END_條,共_TOTAL_條記錄",
          93. "sInfoFiltered" : "數據表中共為 _MAX_ 條記錄",
          94. "sSearch" : "",
          95. "oPaginate" : {
          96. "sFirst" : "首頁",
          97. "sPrevious" : "上一頁",
          98. "sNext" : "下一頁",
          99. "sLast" : "末頁"
          100. }
          101. }, // 多語言配置
          102. "stateSave" : true
          103. // save the state of a table
          104. });
          105. }
          106. }

          藍藍設計建立了UI設計分享群,每天會分享國內外的一些優秀設計,如果有興趣的話,可以進入一起成長學習,請掃碼藍小助,報下信息,藍小助會請您入群。歡迎您加入噢~~希望得到建議咨詢、商務合作,也請與我們聯系。

          截屏2021-05-13 上午11.41.03.png


          分享此文一切功德,皆悉回向給文章原作者及眾讀者.

          免責聲明:藍藍設計尊重原作者,文章的版權歸原作者。如涉及版權問題,請及時與我們取得聯系,我們立即更正或刪除。

          藍藍設計www.syprn.cn )是一家專注而深入的界面設計公司,為期望卓越的國內外企業提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網站建設 、平面設計服務

          日歷

          鏈接

          個人資料

          藍藍設計的小編 http://www.syprn.cn

          存檔

          亚洲va欧美va天堂v国产综合