docs.js 27 KB

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