docs.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  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: 'rowStyle',
  270. attribute: 'data-row-style',
  271. type: 'Function',
  272. description: 'The row formatter function, take two parameters: <br>row: the row record data.<br>index: the row index.<br>Support classes or css.',
  273. 'default': '{}',
  274. example: 'classes-table'
  275. }
  276. ]
  277. });
  278. $('#column').bootstrapTable({
  279. cardView: cardView,
  280. columns: [
  281. {field: 'name', title: 'Name', align: 'center', valign: 'middle', width: 60, sortable: true},
  282. {field: 'attribute', title: 'Attribute', align: 'center', valign: 'middle'},
  283. {field: 'type', title: 'Type', align: 'center', valign: 'middle', width: 60},
  284. {field: 'description', title: 'Description', valign: 'middle', width: 400},
  285. {field: 'default', title: 'Default', align: 'right', valign: 'middle', width: 180},
  286. {field: 'example', title: '', valign: 'middle', formatter: function (value) {
  287. if (!value) {
  288. return '-';
  289. }
  290. return [
  291. '<a title="Example" href="examples.html#' + value + '">',
  292. '<i class="glyphicon glyphicon-eye-open"></i>',
  293. '</a>'].join('');
  294. }}
  295. ],
  296. data: [
  297. {
  298. name: 'radio',
  299. attribute: 'data-radio',
  300. type: 'Boolean',
  301. description: 'True to show a radio. The radio column has fixed width.',
  302. 'default': 'false',
  303. example: 'radio-table'
  304. },
  305. {
  306. name: 'checkbox',
  307. attribute: 'data-checkbox',
  308. type: 'Boolean',
  309. description: 'True to show a checkbox. The checkbox column has fixed width.',
  310. 'default': 'false',
  311. example: 'checkbox-table'
  312. },
  313. {
  314. name: 'field',
  315. attribute: 'data-field',
  316. type: 'String',
  317. description: 'The column field name.',
  318. 'default': 'undefined',
  319. example: 'via-javascript-table'
  320. },
  321. {
  322. name: 'title',
  323. attribute: 'data-title',
  324. type: 'String',
  325. description: 'The column title text.',
  326. 'default': 'undefined',
  327. example: 'via-javascript-table'
  328. },
  329. {
  330. name: 'class',
  331. attribute: 'class / data-class',
  332. type: 'String',
  333. description: 'The column class name.',
  334. 'default': 'undefined',
  335. example: 'classes-table'
  336. },
  337. {
  338. name: 'align',
  339. attribute: 'data-align',
  340. type: 'String',
  341. description: 'Indicate how to align the column data. "left", "right", "center" can be used.',
  342. 'default': 'undefined',
  343. example: 'via-javascript-table'
  344. },
  345. {
  346. name: 'valign',
  347. attribute: 'data-valign',
  348. type: 'String',
  349. description: 'Indicate how to align the cell data. "top", "middle", "bottom" can be used.',
  350. 'default': 'undefined',
  351. example: 'via-javascript-table'
  352. },
  353. {
  354. name: 'width',
  355. attribute: 'data-width',
  356. type: 'Number',
  357. description: 'The width of column. If not defined, the width will auto expand to fit its contents.',
  358. 'default': 'undefined',
  359. example: ''
  360. },
  361. {
  362. name: 'sortable',
  363. attribute: 'data-sortable',
  364. type: 'Boolean',
  365. description: 'True to allow the column can be sorted.',
  366. 'default': 'false',
  367. example: 'sort-table'
  368. },
  369. {
  370. name: 'order',
  371. attribute: 'data-order',
  372. type: 'String',
  373. description: 'The default sort order, can only be "asc" or "desc".',
  374. 'default': 'asc',
  375. example: 'sort-table'
  376. },
  377. {
  378. name: 'visible',
  379. attribute: 'data-visible',
  380. type: 'Boolean',
  381. description: 'True to visible the columns item.',
  382. 'default': 'true',
  383. example: 'show-columns-table'
  384. },
  385. {
  386. name: 'switchable',
  387. attribute: 'data-switchable',
  388. type: 'Boolean',
  389. description: 'False to disable the switchable of columns item.',
  390. 'default': 'true',
  391. example: 'show-columns-table'
  392. },
  393. {
  394. name: 'formatter',
  395. attribute: 'data-formatter',
  396. type: 'Function',
  397. description: 'The cell formatter function, take two parameters: <br />value: the field value. <br />row: the row record data.<br />index: the row index.',
  398. 'default': 'undefined',
  399. example: 'format-table'
  400. },
  401. {
  402. name: 'sorter',
  403. attribute: 'data-sorter',
  404. type: 'Function',
  405. 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.',
  406. 'default': 'undefined',
  407. example: 'custom-sort-table'
  408. }
  409. ]
  410. });
  411. $('#event').bootstrapTable({
  412. cardView: cardView,
  413. columns: [
  414. {field: 'name', title: 'Option Event', align: 'center', valign: 'middle', width: 100, sortable: true},
  415. {field: 'event', title: 'jQuery Event', align: 'center', valign: 'middle', width: 100, sortable: true},
  416. {field: 'parameter', title: 'Parameter', align: 'center', valign: 'middle', width: 100, sortable: true},
  417. {field: 'description', title: 'Description', width: 400, sortable: true}
  418. ],
  419. data: [
  420. {
  421. name: 'onAll',
  422. event: 'all.bs.table',
  423. parameter: 'name, args',
  424. description: 'Fires when all events trigger, the parameters contains: <br />name: the event name, <br>args: the event data.'
  425. },
  426. {
  427. name: 'onClickRow',
  428. event: 'click-row.bs.table',
  429. parameter: 'row, $element',
  430. description: 'Fires when user click a row, the parameters contains: <br />row: the record corresponding to the clicked row, <br>$element: the tr element.'
  431. },
  432. {
  433. name: 'onDblClickRow',
  434. event: 'dbl-click-row.bs.table',
  435. parameter: 'row, $element',
  436. description: 'Fires when user click a row, the parameters contains: <br />row: the record corresponding to the clicked row, <br>$element: the tr element.'
  437. },
  438. {
  439. name: 'onSort',
  440. event: 'sort.bs.table',
  441. parameter: 'name, order',
  442. description: 'Fires when user sort a column, the parameters contains: <br />name: the sort column field name<br />order: the sort column order.'
  443. },
  444. {
  445. name: 'onCheck',
  446. event: 'check.bs.table',
  447. parameter: 'row',
  448. description: 'Fires when user check a row, the parameters contains: <br />row: the record corresponding to the clicked row.'
  449. },
  450. {
  451. name: 'onUncheck',
  452. event: 'uncheck.bs.table',
  453. parameter: 'row',
  454. description: 'Fires when user uncheck a row, the parameters contains: <br />row: the record corresponding to the clicked row.'
  455. },
  456. {
  457. name: 'onCheckAll',
  458. event: 'check-all.bs.table',
  459. parameter: 'none',
  460. description: 'Fires when user check all rows.'
  461. },
  462. {
  463. name: 'onUncheckAll',
  464. event: 'uncheck-all.bs.table',
  465. parameter: 'none',
  466. description: 'Fires when user uncheck all rows.'
  467. },
  468. {
  469. name: 'onLoadSuccess',
  470. event: 'load-success.bs.table',
  471. parameter: 'data',
  472. description: 'Fires when remote data is loaded successfully.'
  473. },
  474. {
  475. name: 'onLoadError',
  476. event: 'load-error.bs.table',
  477. parameter: 'status',
  478. description: 'Fires when some errors occur to load remote data.'
  479. }
  480. ],
  481. onClickRow: function (row) {
  482. console.log('onClickRow', row);
  483. },
  484. onSort: function (name, order) {
  485. console.log('onSort', name, order);
  486. },
  487. onCheck: function(row) {
  488. console.log('onCheck', row);
  489. },
  490. onUncheck: function(row) {
  491. console.log('onUncheck', row);
  492. },
  493. onCheckAll: function() {
  494. console.log('onCheckAll');
  495. },
  496. onUncheckAll: function() {
  497. console.log('onUncheckAll');
  498. }
  499. });
  500. $('#method').bootstrapTable({
  501. cardView: cardView,
  502. columns: [
  503. {field: 'name', title: 'Name', align: 'center', valign: 'middle', width: 100},
  504. {field: 'parameter', title: 'Parameter', align: 'center', valign: 'middle', width: 100},
  505. {field: 'description', title: 'Description', width: 400}
  506. ]
  507. }).bootstrapTable('load', [
  508. {name: 'getSelections', parameter: 'none', description: 'Return all selected rows, when no record selected, am empty array will return.'},
  509. {name: 'load', parameter: 'data', description: 'Load the data to table.'}
  510. ]).bootstrapTable('append', [
  511. {name: 'append', parameter: 'data', description: 'Append the data to table.'},
  512. {name: 'mergeCells', parameter: 'options', description: 'Merge some cells to one cell, the options contains following properties:'},
  513. {name: 'mergeCells', parameter: 'options', description: 'index: the row index.'},
  514. {name: 'mergeCells', parameter: 'options', description: 'field: the field name.'},
  515. {name: 'mergeCells', parameter: 'options', description: 'rowspan: the rowspan count to be merged.'},
  516. {name: 'mergeCells', parameter: 'options', description: 'colspan: the colspan count to be merged.'},
  517. {name: 'refresh', parameter: 'none', description: 'Refresh the remote server data.'},
  518. {name: 'showLoading', parameter: 'none', description: 'Show loading status.'},
  519. {name: 'hideLoading', parameter: 'none', description: 'Hide loading status.'},
  520. {name: 'checkAll', parameter: 'none', description: 'Check all current page rows.'},
  521. {name: 'uncheckAll', parameter: 'none', description: 'Uncheck all current page rows.'},
  522. {name: 'resetView', parameter: 'params', description: 'Reset the bootstrap table view, for example reset the table height.'},
  523. {name: 'destroy', parameter: 'none', description: 'Destroy the bootstrap table.'}
  524. ]).bootstrapTable('mergeCells', {
  525. index: 3,
  526. field: 'name',
  527. rowspan: 5
  528. }).bootstrapTable('mergeCells', {
  529. index: 3,
  530. field: 'parameter',
  531. rowspan: 5
  532. });
  533. $('#localization').bootstrapTable({
  534. cardView: cardView,
  535. columns: [
  536. {field: 'name', title: 'Name', align: 'center', valign: 'middle', width: 100},
  537. {field: 'parameter', title: 'Parameter', align: 'center', valign: 'middle', width: 100},
  538. {field: 'default', title: 'Default', align: 'center', valign: 'middle', width: 200}
  539. ],
  540. data: [{
  541. name: 'formatLoadingMessage',
  542. parameter: '-',
  543. 'default': 'Loading, please wait…'
  544. }, {
  545. name: 'formatRecordsPerPage',
  546. parameter: 'pageNumber',
  547. 'default': '%s records per page'
  548. }, {
  549. name: 'formatShowingRows',
  550. parameter: 'pageFrom, pageTo, totalRows',
  551. 'default': 'Showing %s to %s of %s rows'
  552. }, {
  553. name: 'formatSearch',
  554. parameter: '-',
  555. 'default': 'Search'
  556. }, {
  557. name: 'formatNoMatches',
  558. parameter: '-',
  559. 'default': 'No matching records found'
  560. }]
  561. });
  562. $('[title]').tooltip();
  563. }
  564. $(window).on('resize', initTables);
  565. initTables();
  566. });