Responsive.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace Dcat\Admin\Grid;
  3. use Dcat\Admin\Admin;
  4. use Dcat\Admin\Grid;
  5. /**
  6. * @see http://gergeo.se/RWD-Table-Patterns/#demo
  7. */
  8. class Responsive
  9. {
  10. /**
  11. * @var Grid
  12. */
  13. protected $grid;
  14. /**
  15. * @var array
  16. */
  17. protected $options = ['addFocusBtn' => false];
  18. public function __construct(Grid $grid)
  19. {
  20. $this->grid = $grid;
  21. $this->options([
  22. 'i18n' => [
  23. 'focus' => trans('admin.responsive.focus'),
  24. 'display' => trans('admin.responsive.display'),
  25. 'displayAll' => trans('admin.responsive.display_all'),
  26. ],
  27. ]);
  28. }
  29. /**
  30. * Show focus button.
  31. *
  32. * @return $this
  33. */
  34. public function focus()
  35. {
  36. return $this->options(['addFocusBtn' => true]);
  37. }
  38. /**
  39. * @return $this
  40. */
  41. public function all()
  42. {
  43. $this->grid->columns()->each->responsive();
  44. return $this;
  45. }
  46. /**
  47. * @param array $options
  48. *
  49. * @return $this
  50. */
  51. public function options(array $options)
  52. {
  53. $this->options = array_merge($this->options, $options);
  54. return $this;
  55. }
  56. public function build()
  57. {
  58. Admin::css('vendor/dcat-admin/RWD-Table-Patterns/dist/css/rwd-table.min.css');
  59. Admin::js('vendor/dcat-admin/RWD-Table-Patterns/dist/js/rwd-table.min.js');
  60. $opt = json_encode($this->options);
  61. if (request()->pjax()) {
  62. Admin::script("$('.table-responsive').responsiveTable($opt);");
  63. } else {
  64. Admin::script("setTimeout(function(){ $('.table-responsive').responsiveTable($opt); },5);");
  65. }
  66. }
  67. }