docs.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. $(function () {
  2. 'use strict';
  3. function initTables() {
  4. var cardView = false;
  5. if ($(window).width() < 640) {
  6. cardView = true;
  7. }
  8. $('#table, #column, #event, #method, #localization').bootstrapTable('destroy');
  9. $('#table').bootstrapTable({
  10. cardView: cardView,
  11. columns: [
  12. {field: 'name', title: 'Name', align: 'center', width: 60, sortable: true},
  13. {field: 'type', title: 'Type', align: 'center', width: 60},
  14. {field: 'description', title: 'Description', width: 400},
  15. {field: 'default', title: 'Default', align: '', width: 180}
  16. ],
  17. data: [
  18. {
  19. name: 'bootstrapVersion',
  20. type: 'Number',
  21. description: 'Bootstrap version.',
  22. 'default': '3'
  23. },
  24. {
  25. name: 'classes',
  26. type: 'String',
  27. description: 'The class name of table.',
  28. 'default': 'table table-hover'
  29. },
  30. {
  31. name: 'height',
  32. type: 'Number',
  33. description: 'The height of table.',
  34. 'default': 'undefined'
  35. },
  36. {
  37. name: 'undefinedText',
  38. type: 'String',
  39. description: 'Defines the default undefined text.',
  40. 'default': '-'
  41. },
  42. {
  43. name: 'striped',
  44. type: 'Boolean',
  45. description: 'True to stripe the rows.',
  46. 'default': 'false'
  47. },
  48. {
  49. name: 'sortName',
  50. type: 'String',
  51. description: 'Defines which column can be sorted.',
  52. 'default': 'undefined'
  53. },
  54. {
  55. name: 'sortOrder',
  56. type: 'String',
  57. description: 'Defines the column sort order, can only be "asc" or "desc".',
  58. 'default': 'asc'
  59. },
  60. {
  61. name: 'columns',
  62. type: 'Array',
  63. description: 'The table columns config object, see column properties for more details.',
  64. 'default': '[]'
  65. },
  66. {
  67. name: 'data',
  68. type: 'Array',
  69. description: 'The data to be loaded.',
  70. 'default': '[]'
  71. },
  72. {
  73. name: 'method',
  74. type: 'String',
  75. description: 'The method type to request remote data.',
  76. 'default': 'get'
  77. },
  78. {
  79. name: 'url',
  80. type: 'String',
  81. description: 'A URL to request data from remote site.',
  82. 'default': 'undefined'
  83. },
  84. {
  85. name: 'contentType',
  86. type: 'String',
  87. description: 'The contentType of request remote data.',
  88. 'default': 'application/json'
  89. },
  90. {
  91. name: 'queryParams',
  92. type: 'Function',
  93. description: 'When request remote data, sending additional parameters by format the queryParams, the parameters object contains: <br>pageSize, pageNumber, searchText, sortName, sortOrder.',
  94. 'default': 'function(params) {<br>return {};<br>}'
  95. },
  96. {
  97. name: 'responseHandler',
  98. type: 'Function',
  99. description: 'Before load remote data, handler the response data format, the parameters object contains: <br>res: the response data.',
  100. 'default': 'function(res) {<br>return res;<br>}'
  101. },
  102. {
  103. name: 'pagination',
  104. type: 'Boolean',
  105. description: 'True to show a pagination toolbar on datagrid bottom.',
  106. 'default': 'false'
  107. },
  108. {
  109. name: 'sidePagination',
  110. type: 'String',
  111. description: 'Defines the side pagination of table, can only be "client" or "server".',
  112. 'default': 'client'
  113. },
  114. {
  115. name: 'totalRows',
  116. type: 'Number',
  117. description: 'Defines the total rows of table, you need to set this option when the sidePagination option is set to "server".',
  118. 'default': 0
  119. },
  120. {
  121. name: 'pageNumber',
  122. type: 'Number',
  123. description: 'When set pagination property, initialize the page number.',
  124. 'default': 1
  125. },
  126. {
  127. name: 'pageSize',
  128. type: 'Number',
  129. description: 'When set pagination property, initialize the page size.',
  130. 'default': 10
  131. },
  132. {
  133. name: 'pageList',
  134. type: 'Array',
  135. description: 'When set pagination property, initialize the page size selecting list.',
  136. 'default': '[10, 25, 50, 100]'
  137. },
  138. {
  139. name: 'search',
  140. type: 'Boolean',
  141. description: 'Enable the search input.',
  142. 'default': 'false'
  143. },
  144. {
  145. name: 'selectItemName',
  146. type: 'String',
  147. description: 'The name of radio or checkbox input.',
  148. 'default': 'btSelectItem'
  149. },
  150. {
  151. name: 'showHeader',
  152. type: 'Boolean',
  153. description: 'False to hide the table header.',
  154. 'default': 'true'
  155. },
  156. {
  157. name: 'showColumns',
  158. type: 'Boolean',
  159. description: 'True to show the columns drop down list.',
  160. 'default': 'false'
  161. },
  162. {
  163. name: 'minimunCountColumns',
  164. type: 'Number',
  165. description: 'The minimun count columns to hide of the columns drop down list.',
  166. 'default': '1'
  167. },
  168. {
  169. name: 'idField',
  170. type: 'String',
  171. description: 'Indicate which field is an identity field.',
  172. 'default': 'undefined'
  173. },
  174. {
  175. name: 'cardView',
  176. type: 'Boolean',
  177. description: 'True to show card view table, for example mobile view.',
  178. 'default': 'false'
  179. },
  180. {
  181. name: 'clickToSelect',
  182. type: 'Boolean',
  183. description: 'True to select checkbox or radiobox when click rows.',
  184. 'default': 'false'
  185. },
  186. {
  187. name: 'singleSelect',
  188. type: 'Boolean',
  189. description: 'True to allow checkbox selecting only one row.',
  190. 'default': 'false'
  191. },
  192. {
  193. name: 'toolbar',
  194. type: 'String',
  195. description: 'A jQuery selector that indicate the toolbar, for example: <br>#toolbar, .toolbar.',
  196. 'default': 'undefined'
  197. },
  198. {
  199. name: 'rowStyle',
  200. type: 'Function',
  201. description: 'The row formatter function, take two parameters: <br>row: the row record data.<br>index: the row index.<br>Support classes or css, code example:<br><pre>return {<br> classes: "red", <br> css: {background: "red", color: "white"}<br>}</pre>',
  202. 'default': '{}'
  203. }
  204. ]
  205. });
  206. $('#column').bootstrapTable({
  207. cardView: cardView,
  208. columns: [
  209. {field: 'name', title: 'Name', align: 'center', valign: 'middle', width: 60, sortable: true},
  210. {field: 'type', title: 'Type', align: 'center', valign: 'middle', width: 60},
  211. {field: 'description', title: 'Description', width: 400},
  212. {field: 'default', title: 'Default', align: 'right', valign: 'middle', width: 180}
  213. ],
  214. data: [
  215. {
  216. name: 'radio',
  217. type: 'Boolean',
  218. description: 'True to show a radio. The radio column has fixed width.',
  219. 'default': 'false'
  220. },
  221. {
  222. name: 'checkbox',
  223. type: 'Boolean',
  224. description: 'True to show a checkbox. The checkbox column has fixed width.',
  225. 'default': 'false'
  226. },
  227. {
  228. name: 'field',
  229. type: 'String',
  230. description: 'The column field name.',
  231. 'default': 'undefined'
  232. },
  233. {
  234. name: 'title',
  235. type: 'String',
  236. description: 'The column title text.',
  237. 'default': 'undefined'
  238. },
  239. {
  240. name: 'align',
  241. type: 'String',
  242. description: 'Indicate how to align the column data. "left", "right", "center" can be used.',
  243. 'default': 'undefined'},
  244. {
  245. name: 'valign',
  246. type: 'String',
  247. description: 'Indicate how to align the cell data. "top", "middle", "bottom" can be used.',
  248. 'default': 'undefined'
  249. },
  250. {
  251. name: 'width',
  252. type: 'Number',
  253. description: 'The width of column. If not defined, the width will auto expand to fit its contents.',
  254. 'default': 'undefined'},
  255. {
  256. name: 'sortable',
  257. type: 'Boolean',
  258. description: 'True to allow the column can be sorted.',
  259. 'default': 'false'
  260. },
  261. {
  262. name: 'order',
  263. type: 'String',
  264. description: 'The default sort order, can only be "asc" or "desc".',
  265. 'default': 'asc'
  266. },
  267. {
  268. name: 'visible',
  269. type: 'Boolean',
  270. description: 'True to visible the columns item.',
  271. 'default': 'true'
  272. },
  273. {
  274. name: 'formatter',
  275. type: 'Function',
  276. description: 'The cell formatter function, take two parameters: <br />value: the field value. <br />row: the row record data.<br />index: the row index.',
  277. 'default': 'undefined'
  278. },
  279. {
  280. name: 'sorter',
  281. type: 'Function',
  282. 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.',
  283. 'default': 'undefined'
  284. }
  285. ]
  286. });
  287. $('#event').bootstrapTable({
  288. cardView: cardView,
  289. columns: [
  290. {field: 'name', title: 'Option Event', align: 'center', valign: 'middle', width: 100, sortable: true},
  291. {field: 'event', title: 'jQuery Event', align: 'center', valign: 'middle', width: 100, sortable: true},
  292. {field: 'parameter', title: 'Parameter', align: 'center', valign: 'middle', width: 100, sortable: true},
  293. {field: 'description', title: 'Description', width: 400, sortable: true}
  294. ],
  295. data: [
  296. {
  297. name: 'onAll',
  298. event: 'all.bs.table',
  299. parameter: 'name, args',
  300. description: 'Fires when all events trigger, the parameters contains: <br />name: the event name, <br>args: the event data.'
  301. },
  302. {
  303. name: 'onClickRow',
  304. event: 'click-row.bs.table',
  305. parameter: 'row, $element',
  306. description: 'Fires when user click a row, the parameters contains: <br />row: the record corresponding to the clicked row, <br>$element: the tr element.'
  307. },
  308. {
  309. name: 'onDblClickRow',
  310. event: 'dbl-click-row.bs.table',
  311. parameter: 'row, $element',
  312. description: 'Fires when user click a row, the parameters contains: <br />row: the record corresponding to the clicked row, <br>$element: the tr element.'
  313. },
  314. {
  315. name: 'onSort',
  316. event: 'sort.bs.table',
  317. parameter: 'name, order',
  318. description: 'Fires when user sort a column, the parameters contains: <br />name: the sort column field name<br />order: the sort column order.'
  319. },
  320. {
  321. name: 'onCheck',
  322. event: 'check.bs.table',
  323. parameter: 'row',
  324. description: 'Fires when user check a row, the parameters contains: <br />row: the record corresponding to the clicked row.'
  325. },
  326. {
  327. name: 'onUncheck',
  328. event: 'uncheck.bs.table',
  329. parameter: 'row',
  330. description: 'Fires when user uncheck a row, the parameters contains: <br />row: the record corresponding to the clicked row.'
  331. },
  332. {
  333. name: 'onCheckAll',
  334. event: 'check-all.bs.table',
  335. parameter: 'none',
  336. description: 'Fires when user check all rows.'
  337. },
  338. {
  339. name: 'onUncheckAll',
  340. event: 'uncheck-all.bs.table',
  341. parameter: 'none',
  342. description: 'Fires when user uncheck all rows.'
  343. },
  344. {
  345. name: 'onLoadSuccess',
  346. event: 'load-success.bs.table',
  347. parameter: 'data',
  348. description: 'Fires when remote data is loaded successfully.'
  349. },
  350. {
  351. name: 'onLoadError',
  352. event: 'load-error.bs.table',
  353. parameter: 'status',
  354. description: 'Fires when some errors occur to load remote data.'
  355. }
  356. ],
  357. onClickRow: function (row) {
  358. console.log('onClickRow', row);
  359. },
  360. onSort: function (name, order) {
  361. console.log('onSort', name, order);
  362. },
  363. onCheck: function(row) {
  364. console.log('onCheck', row);
  365. },
  366. onUncheck: function(row) {
  367. console.log('onUncheck', row);
  368. },
  369. onCheckAll: function() {
  370. console.log('onCheckAll');
  371. },
  372. onUncheckAll: function() {
  373. console.log('onUncheckAll');
  374. }
  375. });
  376. $('#method').bootstrapTable({
  377. cardView: cardView,
  378. columns: [
  379. {field: 'name', title: 'Name', align: 'center', valign: 'middle', width: 100},
  380. {field: 'parameter', title: 'Parameter', align: 'center', valign: 'middle', width: 100},
  381. {field: 'description', title: 'Description', width: 400}
  382. ]
  383. }).bootstrapTable('load', [
  384. {name: 'getSelections', parameter: 'none', description: 'Return all selected rows, when no record selected, am empty array will return.'},
  385. {name: 'load', parameter: 'data', description: 'Load the data to table.'}
  386. ]).bootstrapTable('append', [
  387. {name: 'append', parameter: 'data', description: 'Append the data to table.'},
  388. {name: 'mergeCells', parameter: 'options', description: 'Merge some cells to one cell, the options contains following properties:'},
  389. {name: 'mergeCells', parameter: 'options', description: 'index: the row index.'},
  390. {name: 'mergeCells', parameter: 'options', description: 'field: the field name.'},
  391. {name: 'mergeCells', parameter: 'options', description: 'rowspan: the rowspan count to be merged.'},
  392. {name: 'mergeCells', parameter: 'options', description: 'colspan: the colspan count to be merged.'},
  393. {name: 'refresh', parameter: 'none', description: 'Refresh the remote server data.'},
  394. {name: 'showLoading', parameter: 'none', description: 'Show loading status.'},
  395. {name: 'hideLoading', parameter: 'none', description: 'Hide loading status.'},
  396. {name: 'checkAll', parameter: 'none', description: 'Check all current page rows.'},
  397. {name: 'uncheckAll', parameter: 'none', description: 'Uncheck all current page rows.'},
  398. {name: 'resetView', parameter: 'none', description: 'Reset the bootstrap table view, like display error when init the table with display: none.'},
  399. {name: 'destroy', parameter: 'none', description: 'Destroy the bootstrap table.'}
  400. ]).bootstrapTable('mergeCells', {
  401. index: 3,
  402. field: 'name',
  403. rowspan: 5
  404. }).bootstrapTable('mergeCells', {
  405. index: 3,
  406. field: 'parameter',
  407. rowspan: 5
  408. });
  409. $('#localization').bootstrapTable({
  410. cardView: cardView,
  411. columns: [
  412. {field: 'name', title: 'Name', align: 'center', valign: 'middle', width: 100},
  413. {field: 'parameter', title: 'Parameter', align: 'center', valign: 'middle', width: 100},
  414. {field: 'default', title: 'Default', align: 'center', valign: 'middle', width: 200}
  415. ],
  416. data: [{
  417. name: 'formatLoadingMessage',
  418. parameter: '-',
  419. 'default': 'Loading, please wait…'
  420. }, {
  421. name: 'formatRecordsPerPage',
  422. parameter: 'pageNumber',
  423. 'default': '%s records per page'
  424. }, {
  425. name: 'formatShowingRows',
  426. parameter: 'pageFrom, pageTo, totalRows',
  427. 'default': 'Showing %s to %s of %s rows'
  428. }, {
  429. name: 'formatSearch',
  430. parameter: '-',
  431. 'default': 'Search'
  432. }, {
  433. name: 'formatNoMatches',
  434. parameter: '-',
  435. 'default': 'No matching records found'
  436. }]
  437. });
  438. }
  439. var $window = $(window);
  440. var $body = $(document.body);
  441. var navHeight = $('.navbar').outerHeight(true) + 10;
  442. $body.scrollspy({
  443. target: '.bs-sidebar',
  444. offset: navHeight
  445. });
  446. $window.on('load', function () {
  447. $body.scrollspy('refresh')
  448. });
  449. $window.on('resize', function() {
  450. initTables();
  451. });
  452. // affix
  453. setTimeout(function () {
  454. var $sideBar = $('.bs-sidebar');
  455. $sideBar.affix({
  456. offset: {
  457. top: function () {
  458. var offsetTop = $sideBar.offset().top;
  459. var sideBarMargin = parseInt($sideBar.children(0).css('margin-top'), 10);
  460. var navOuterHeight = $('.bs-docs-nav').height();
  461. return (this.top = offsetTop - navOuterHeight - sideBarMargin);
  462. },
  463. bottom: function () {
  464. return (this.bottom = $('.bs-footer').outerHeight(true));
  465. }
  466. }
  467. });
  468. }, 100);
  469. initTables();
  470. });