multitable.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init();
  6. //绑定事件
  7. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  8. var panel = $($(this).attr("href"));
  9. if (panel.size() > 0) {
  10. Controller.table[panel.attr("id")].call(this);
  11. $(this).on('click', function (e) {
  12. $($(this).attr("href")).find(".btn-refresh").trigger("click");
  13. });
  14. }
  15. //移除绑定的事件
  16. $(this).unbind('shown.bs.tab');
  17. });
  18. //必须默认触发shown.bs.tab事件
  19. $('ul.nav-tabs li.active a[data-toggle="tab"]').trigger("shown.bs.tab");
  20. },
  21. table: {
  22. first: function () {
  23. // 表格1
  24. var table1 = $("#table1");
  25. table1.bootstrapTable({
  26. url: 'example/multitable/table1',
  27. toolbar: '#toolbar1',
  28. sortName: 'id',
  29. search: false,
  30. columns: [
  31. [
  32. {field: 'state', checkbox: true, },
  33. {field: 'id', title: 'ID'},
  34. {field: 'url', title: __('Url'), formatter: Table.api.formatter.url},
  35. {field: 'imagewidth', title: __('Imagewidth')},
  36. {field: 'imageheight', title: __('Imageheight')},
  37. {field: 'mimetype', title: __('Mimetype')},
  38. {field: 'operate', title: __('Operate'), table: table1, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  39. ]
  40. ]
  41. });
  42. // 为表格1绑定事件
  43. Table.api.bindevent(table1);
  44. },
  45. second: function () {
  46. // 表格2
  47. var table2 = $("#table2");
  48. table2.bootstrapTable({
  49. url: 'example/multitable/table2',
  50. extend: {
  51. index_url: '',
  52. add_url: '',
  53. edit_url: '',
  54. del_url: '',
  55. multi_url: '',
  56. table: '',
  57. },
  58. toolbar: '#toolbar2',
  59. sortName: 'id',
  60. search: false,
  61. columns: [
  62. [
  63. {field: 'id', title: 'ID'},
  64. {field: 'title', title: __('Title')},
  65. {field: 'url', title: __('Url'), align: 'left', formatter: Table.api.formatter.url},
  66. {field: 'ip', title: __('ip')},
  67. {field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
  68. ]
  69. ]
  70. });
  71. // 为表格2绑定事件
  72. Table.api.bindevent(table2);
  73. }
  74. },
  75. add: function () {
  76. Controller.api.bindevent();
  77. },
  78. edit: function () {
  79. Controller.api.bindevent();
  80. },
  81. api: {
  82. bindevent: function () {
  83. Form.api.bindevent($("form[role=form]"));
  84. },
  85. }
  86. };
  87. return Controller;
  88. });