docs.js 26 KB

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