buttons.server-side.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. (function ($, DataTable) {
  2. "use strict";
  3. var _buildUrl = function(dt, action) {
  4. var url = dt.ajax.url() || '';
  5. var params = dt.ajax.params();
  6. params.action = action;
  7. return url + '?' + $.param(params);
  8. };
  9. DataTable.ext.buttons.excel = {
  10. className: 'buttons-excel',
  11. text: function (dt) {
  12. return '<i class="fa fa-file-excel-o"></i> ' + dt.i18n('buttons.excel', 'Excel');
  13. },
  14. action: function (e, dt, button, config) {
  15. var url = _buildUrl(dt, 'excel');
  16. window.location = url;
  17. }
  18. };
  19. DataTable.ext.buttons.export = {
  20. extend: 'collection',
  21. className: 'buttons-export',
  22. text: function (dt) {
  23. return '<i class="fa fa-download"></i> ' + dt.i18n('buttons.export', 'Export') + '&nbsp;<span class="caret"/>';
  24. },
  25. buttons: ['csv', 'excel', 'pdf']
  26. };
  27. DataTable.ext.buttons.csv = {
  28. className: 'buttons-csv',
  29. text: function (dt) {
  30. return '<i class="fa fa-file-excel-o"></i> ' + dt.i18n('buttons.csv', 'CSV');
  31. },
  32. action: function (e, dt, button, config) {
  33. var url = _buildUrl(dt, 'csv');
  34. window.location = url;
  35. }
  36. };
  37. DataTable.ext.buttons.pdf = {
  38. className: 'buttons-pdf',
  39. text: function (dt) {
  40. return '<i class="fa fa-file-pdf-o"></i> ' + dt.i18n('buttons.pdf', 'PDF');
  41. },
  42. action: function (e, dt, button, config) {
  43. var url = _buildUrl(dt, 'pdf');
  44. window.location = url;
  45. }
  46. };
  47. DataTable.ext.buttons.print = {
  48. className: 'buttons-print',
  49. text: function (dt) {
  50. return '<i class="fa fa-print"></i> ' + dt.i18n('buttons.print', 'Print');
  51. },
  52. action: function (e, dt, button, config) {
  53. var url = _buildUrl(dt, 'print');
  54. window.location = url;
  55. }
  56. };
  57. DataTable.ext.buttons.reset = {
  58. className: 'buttons-reset',
  59. text: function (dt) {
  60. return '<i class="fa fa-undo"></i> ' + dt.i18n('buttons.reset', 'Reset');
  61. },
  62. action: function (e, dt, button, config) {
  63. dt.search('').draw();
  64. }
  65. };
  66. DataTable.ext.buttons.reload = {
  67. className: 'buttons-reload',
  68. text: function (dt) {
  69. return '<i class="fa fa-refresh"></i> ' + dt.i18n('buttons.reload', 'Reload');
  70. },
  71. action: function (e, dt, button, config) {
  72. dt.draw(false);
  73. }
  74. };
  75. DataTable.ext.buttons.create = {
  76. className: 'buttons-create',
  77. text: function (dt) {
  78. return '<i class="fa fa-plus"></i> ' + dt.i18n('buttons.create', 'Create');
  79. },
  80. action: function (e, dt, button, config) {
  81. window.location = window.location.href.replace(/\/+$/, "") + '/create';
  82. }
  83. };
  84. })(jQuery, jQuery.fn.dataTable);