docs.js 20 KB

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