controllerjump.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'example/controllerjump/index',
  8. add_url: '',
  9. edit_url: '',
  10. del_url: 'example/controllerjump/del',
  11. multi_url: '',
  12. }
  13. });
  14. var table = $("#table");
  15. // 初始化表格
  16. table.bootstrapTable({
  17. url: $.fn.bootstrapTable.defaults.extend.index_url,
  18. columns: [
  19. [
  20. {field: 'state', checkbox: true, },
  21. {field: 'id', title: 'ID'},
  22. {field: 'admin_id', title: __('Admin_id')},
  23. {field: 'title', title: __('Title')},
  24. {field: 'ip', title: __('IP'),formatter: Controller.api.formatter.ip},
  25. {field: 'createtime', title: __('Create time'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
  26. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  27. ]
  28. ]
  29. });
  30. // 为表格绑定事件
  31. Table.api.bindevent(table);
  32. },
  33. add: function () {
  34. Form.api.bindevent($("form[role=form]"));
  35. },
  36. edit: function () {
  37. Form.api.bindevent($("form[role=form]"));
  38. },
  39. api: {
  40. formatter: {
  41. ip: function (value, row, index) {
  42. //这里手动构造URL
  43. url = "example/bootstraptable?" + this.field + "=" + value;
  44. //方式一,直接返回class带有addtabsit的链接,这可以方便自定义显示内容
  45. //return '<a href="' + url + '" class="label label-success addtabsit" title="' + __("Search %s", value) + '">' + __('Search %s', value) + '</a>';
  46. //方式二,直接调用Table.api.formatter.addtabs
  47. this.url = url;
  48. return Table.api.formatter.addtabs.call(this, value, row, index);
  49. }
  50. }
  51. }
  52. };
  53. return Controller;
  54. });