index.html 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>bootstrap-table demo</title>
  6. <meta name="author" content="zhixin" />
  7. <meta name="viewport" content="width=device-width; initial-scale=1.0" />
  8. <link rel="stylesheet" href="/css/bootstrap.css" />
  9. <link rel="stylesheet" href="/css/fork.css" />
  10. <link rel="stylesheet" href="bootstrap-table.css" />
  11. <style>
  12. body {
  13. margin-bottom: 50px;
  14. }
  15. #example {
  16. height: 200px;
  17. }
  18. </style>
  19. </head>
  20. <body>
  21. <div class="container">
  22. <h3>Table Properties:</h3>
  23. <table id="table"></table>
  24. <h3>Column Properties:</h3>
  25. <table id="column"></table>
  26. <h3>Events:</h3>
  27. <table id="event"></table>
  28. <h3>Methods:</h3>
  29. <table id="method"></table>
  30. <h3>Examples:</h3>
  31. <table id="example"></table>
  32. </div>
  33. <a href="https://github.com/wenzhixin/bootstrap-table" class="fork_me"></a>
  34. <script type="text/javascript" src="/js/jquery-1.8.3.min.js"></script>
  35. <script type="text/javascript" src="jquery.bootstrap.table.js"></script>
  36. <script type="text/javascript">
  37. $(function() {
  38. $('#table').bootstrapTable({
  39. columns: [
  40. {field: 'name', title: 'Name', align: 'center', width: 60, sortable: true},
  41. {field: 'type', title: 'Type', align: 'center', width: 60},
  42. {field: 'description', title: 'Description', width: 400},
  43. {field: 'default', title: 'Default', align: 'right', width: 180}
  44. ],
  45. data: [
  46. {name: 'sortName', type: 'String', description: 'Defines which column can be sorted.', 'default': 'undefined'},
  47. {name: 'sortOrder', type: 'String', description: 'Defines the column sort order, can only be "asc" or "desc".', 'default': 'asc'},
  48. {name: 'columns', type: 'Array', description: 'The table columns config object, see column properties for more details.', 'default': '[]'},
  49. {name: 'data', type: 'Array', description: 'The data to be loaded.', 'default': '[]'}
  50. ]
  51. });
  52. $('#column').bootstrapTable({
  53. sortName: 'name',
  54. sortOrder: 'asc',
  55. columns: [
  56. {field: 'name', title: 'Name', align: 'center', valign: 'middle', width: 60, sortable: true},
  57. {field: 'type', title: 'Type', align: 'center', valign: 'middle', width: 60},
  58. {field: 'description', title: 'Description', width: 400},
  59. {field: 'default', title: 'Default', align: 'right', valign: 'middle', width: 180}
  60. ],
  61. data: [
  62. {name: 'field', type: 'String', description: 'The column field name.', 'default': 'undefined'},
  63. {name: 'title', type: 'String', description: 'The column title text.', 'default': 'undefined'},
  64. {name: 'align', type: 'String', description: 'Indicate how to align the column data. "left", "right", "center" can be used.', 'default': 'undefined'},
  65. {name: 'valign', type: 'String', description: 'Indicate how to align the cell data. "top", "middle", "bottom" can be used.', 'default': 'undefined'},
  66. {name: 'width', type: 'Number', description: 'The width of column. If not defined, the width will auto expand to fit its contents.', 'default': 'undefined'},
  67. {name: 'sortable', type: 'Boolean', description: 'True to allow the column can be sorted.', 'default': 'false'},
  68. {name: 'order', type: 'String', description: 'The default sort order, can only be "asc" or "desc".', 'default': 'asc'},
  69. {name: 'formatter', type: 'Function', description: 'The cell formatter function, take two parameters: <br />value: the field value. <br />row: the row record data.', 'default': 'undefined'},
  70. {name: 'sorter', type: 'Function', description: 'The custom field sort function that used to do local sorting, take two parameters: <br />a: the first field value.<br /> b: the second field value.', 'default': 'undefined'}
  71. ]
  72. });
  73. $('#event').bootstrapTable({
  74. columns: [
  75. {field: 'name', title: 'Name', align: 'center', valign: 'middle', width: 100, sortable: true},
  76. {field: 'parameter', title: 'Parameter', align: 'center', valign: 'middle', width: 100, sortable: true},
  77. {field: 'description', title: 'Description', width: 400, sortable: true}
  78. ],
  79. data: [
  80. {name: 'onClickRow', parameter: 'row', description: 'Fires when user click a row, the parameters contains: <br />row: the record corresponding to the clicked row'},
  81. {name: 'onSort', parameter: 'name, order', description: 'Fires when user sort a column, the parameters contains: <br />name: the sort column field name<br />order: the sort column order'}
  82. ],
  83. onClickRow: function(row) {
  84. console.log(row);
  85. },
  86. onSort: function(name, order) {
  87. console.log(name, order);
  88. }
  89. });
  90. $('#method').bootstrapTable({
  91. columns: [
  92. {field: 'name', title: 'Name', align: 'center', valign: 'middle', width: 100},
  93. {field: 'parameter', title: 'Parameter', align: 'center', valign: 'middle', width: 100},
  94. {field: 'description', title: 'Description', width: 400}
  95. ]
  96. }).bootstrapTable('load', [
  97. {name: 'load', parameter: 'data', description: 'Load the data to table.'}
  98. ]).bootstrapTable('append', [
  99. {name: 'append', parameter: 'data', description: 'Append the data to table.'},
  100. {name: 'mergeCells', parameter: 'options', description: 'Merge some cells to one cell, the options contains following properties:'},
  101. {name: 'mergeCells', parameter: 'options', description: 'index: the row index.'},
  102. {name: 'mergeCells', parameter: 'options', description: 'field: the field name.'},
  103. {name: 'mergeCells', parameter: 'options', description: 'rowspan: the rowspan count to be merged.'},
  104. {name: 'mergeCells', parameter: 'options', description: 'colspan: the colspan count to be merged.'}
  105. ]).bootstrapTable('mergeCells', {
  106. index: 2,
  107. field: 'name',
  108. rowspan: 5
  109. }).bootstrapTable('mergeCells', {
  110. index: 2,
  111. field: 'parameter',
  112. rowspan: 5
  113. });
  114. var data = [];
  115. for (var i = 100; i < 1000; i++) {
  116. data.push({code: '' + i, name: 'hello ' + i, price: '$' + i});
  117. }
  118. $('#example').bootstrapTable({
  119. sortName: 'code',
  120. sortOrder: 'asc',
  121. columns: [
  122. {field: 'code', title: 'Code', align: 'left', width: 200, sortable: true},
  123. {field: 'name', title: 'Name', align: 'center', width: 100},
  124. {field: 'price', title: 'Price', align: 'right', valign: 'middle', width: 200, formatter: function(value, row) {
  125. return 'the price is: ' + value;
  126. }}
  127. ],
  128. data: data
  129. });
  130. });
  131. </script>
  132. <script type="text/javascript" src="/js/analytics.js"></script>
  133. </body>
  134. </html>