bootstrap-table-filter.js 1.9 KB

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