docs.js 26 KB

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