bootstrap-table-filter.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. (function (global, factory) {
  2. if (typeof define === "function" && define.amd) {
  3. define([], factory);
  4. } else if (typeof exports !== "undefined") {
  5. factory();
  6. } else {
  7. var mod = {
  8. exports: {}
  9. };
  10. factory();
  11. global.bootstrapTableFilter = mod.exports;
  12. }
  13. })(this, function () {
  14. 'use strict';
  15. /**
  16. * @author zhixin wen <wenzhixin2010@gmail.com>
  17. * extensions: https://github.com/lukaskral/bootstrap-table-filter
  18. */
  19. !function ($) {
  20. 'use strict';
  21. $.extend($.fn.bootstrapTable.defaults, {
  22. showFilter: false
  23. });
  24. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  25. _init = BootstrapTable.prototype.init,
  26. _initSearch = BootstrapTable.prototype.initSearch;
  27. BootstrapTable.prototype.init = function () {
  28. _init.apply(this, Array.prototype.slice.apply(arguments));
  29. var that = this;
  30. this.$el.on('load-success.bs.table', function () {
  31. if (that.options.showFilter) {
  32. $(that.options.toolbar).bootstrapTableFilter({
  33. connectTo: that.$el
  34. });
  35. }
  36. });
  37. };
  38. BootstrapTable.prototype.initSearch = function () {
  39. _initSearch.apply(this, Array.prototype.slice.apply(arguments));
  40. if (this.options.sidePagination !== 'server') {
  41. if (typeof this.searchCallback === 'function') {
  42. this.data = $.grep(this.options.data, this.searchCallback);
  43. }
  44. }
  45. };
  46. BootstrapTable.prototype.getData = function () {
  47. return this.searchText || this.searchCallback ? this.data : this.options.data;
  48. };
  49. BootstrapTable.prototype.getColumns = function () {
  50. return this.columns;
  51. };
  52. BootstrapTable.prototype.registerSearchCallback = function (callback) {
  53. this.searchCallback = callback;
  54. };
  55. BootstrapTable.prototype.updateSearch = function () {
  56. this.options.pageNumber = 1;
  57. this.initSearch();
  58. this.updatePagination();
  59. };
  60. BootstrapTable.prototype.getServerUrl = function () {
  61. return this.options.sidePagination === 'server' ? this.options.url : false;
  62. };
  63. $.fn.bootstrapTable.methods.push('getColumns', 'registerSearchCallback', 'updateSearch', 'getServerUrl');
  64. }(jQuery);
  65. });