bootstrap.html 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>HTML table Export</title>
  6. <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
  7. <script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.bundle.min.js"></script>
  8. <script src="https://unpkg.com/bootstrap-table@1.18.3/dist/bootstrap-table.min.js"></script>
  9. <script src="https://unpkg.com/bootstrap-table@1.18.3/dist/extensions/export/bootstrap-table-export.js"></script>
  10. <script src="https://unpkg.com/bootstrap-table@1.18.3/dist/extensions/toolbar/bootstrap-table-toolbar.js"></script>
  11. <script type="text/javascript" src="../tableExport.js"></script>
  12. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  13. <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
  14. <link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.18.3/dist/bootstrap-table.min.css">
  15. <script type="text/javaScript">
  16. function detailFormatter(index, row) {
  17. var html = [];
  18. $.each(row, function (key, value) {
  19. html.push('<p><b>' + key + ':</b> ' + value + '</p>');
  20. });
  21. return html.join('');
  22. }
  23. function DoOnCellHtmlData(cell, row, col, data) {
  24. var result = "";
  25. if (typeof data != 'undefined' && data != "") {
  26. var html = $.parseHTML(data);
  27. $.each( html, function() {
  28. if ( typeof $(this).html() === 'undefined' )
  29. result += $(this).text();
  30. else if ( typeof $(this).attr('class') === 'undefined' || $(this).hasClass('th-inner') === true )
  31. result += $(this).html();
  32. });
  33. }
  34. return result;
  35. }
  36. $(function () {
  37. $('#toolbar').find('select').change(function () {
  38. $('#table').bootstrapTable('refreshOptions', {
  39. exportDataType: $(this).val()
  40. });
  41. });
  42. })
  43. $(document).ready(function()
  44. {
  45. $('#table').bootstrapTable('refreshOptions', {
  46. exportOptions: {ignoreColumn: [0,1], // or as string array: ['0','checkbox']
  47. onCellHtmlData: DoOnCellHtmlData}
  48. });
  49. });
  50. </script>
  51. </head>
  52. <body>
  53. <div class="container">
  54. <h1 align="center">Data</h1><br>
  55. <div id="toolbar">
  56. <select class="form-control">
  57. <option value="">Export Basic</option>
  58. <option value="all">Export All</option>
  59. <option value="selected">Export Selected</option>
  60. </select>
  61. </div>
  62. <table id="table"
  63. data-toggle="table"
  64. data-height="600"
  65. data-show-toggle="true"
  66. data-show-columns="true"
  67. data-show-export="true"
  68. data-click-to-select="true"
  69. data-toolbar="#toolbar"
  70. data-pagination="true"
  71. data-search="true"
  72. data-detail-view="true"
  73. data-detail-formatter="detailFormatter"
  74. data-filter-control="true"
  75. data-url="tableExport.json">
  76. <thead>
  77. <tr>
  78. <th data-field="checkbox" data-checkbox="true" > </th>
  79. <th data-field="Rank" data-sortable="true" data-filter-control="select" data-visible="true" >Rank </th>
  80. <th data-field="Flag" data-sortable="true" data-filter-control="input" data-visible="false" >Flag </th>
  81. <th data-field="Country" data-sortable="true" data-filter-control="select" data-visible="true" >Country </th>
  82. <th data-field="Population" data-sortable="true" data-filter-control="select" data-visible="false" >Population </th>
  83. <th data-field="Date" data-sortable="true" data-filter-control="select" data-visible="true" >Date </th>
  84. <th data-field="p_of_world" data-sortable="true" data-filter-control="select" data-visible="false" >% of world </th>
  85. <th data-field="Language" data-sortable="true" data-filter-control="select" data-visible="true" >Language </th>
  86. </tr>
  87. </thead>
  88. </table>
  89. </div>
  90. </body>
  91. </html>