AsyncTable.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /**
  2. * 异步渲染表格
  3. */
  4. export default class AsyncTable {
  5. constructor(options) {
  6. this.options = $.extend({
  7. container: '.table-card',
  8. }, options);
  9. let _this = this;
  10. $(this.options.container).on('table:load', function () {
  11. _this.load($(this).data('url'), $(this));
  12. });
  13. }
  14. load(url, box) {
  15. let _this = this;
  16. if (! url) {
  17. return;
  18. }
  19. // 缓存当前请求地址
  20. box.attr('data-current', url);
  21. box.loading({background: 'transparent!important'});
  22. Dcat.helpers.asyncRender(url, function (html) {
  23. box.loading(false);
  24. box.html(html);
  25. _this.bind(box);
  26. box.trigger('table:loaded');
  27. });
  28. }
  29. bind(box) {
  30. let _this = this;
  31. function loadLink() {
  32. _this.load($(this).attr('href'), box);
  33. return false;
  34. }
  35. box.find('.pagination .page-link').on('click', loadLink);
  36. box.find('.grid-column-header a').on('click', loadLink);
  37. box.find('form').on('submit', function () {
  38. _this.load($(this).attr('action')+'&'+$(this).serialize(), box);
  39. return false;
  40. });
  41. box.find('.filter-box .reset').on('click', loadLink);
  42. box.find('.grid-selector a').on('click', loadLink);
  43. Dcat.ready(function () {
  44. setTimeout(function () {
  45. box.find('.grid-refresh').off('click').on('click', function () {
  46. _this.load(box.data('current'), box);
  47. return false;
  48. })
  49. }, 10)
  50. })
  51. }
  52. }