DistUserTable.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace App\Admin\Renderable;
  3. use Dcat\Admin\Grid;
  4. use Dcat\Admin\Grid\LazyRenderable;
  5. use App\Models\DistAdminUser;
  6. class DistUserTable extends LazyRenderable
  7. {
  8. public function grid(): Grid
  9. {
  10. // 获取外部传递的参数
  11. $id = $this->id;
  12. return Grid::make(new DistAdminUser(), function (Grid $grid) {
  13. $grid->column('id');
  14. $grid->column('username');
  15. $grid->column('name');
  16. $grid->column('created_at');
  17. $grid->column('updated_at');
  18. // 指定行选择器选中时显示的值的字段名称
  19. // 指定行选择器选中时显示的值的字段名称
  20. // 指定行选择器选中时显示的值的字段名称
  21. // 如果表格数据中带有 “name”、“title”或“username”字段,则可以不用设置
  22. $grid->rowSelector()->titleColumn('name');
  23. $grid->quickSearch(['id', 'username', 'name']);
  24. $grid->paginate(10);
  25. $grid->disableActions();
  26. $grid->filter(function (Grid\Filter $filter) {
  27. $filter->like('username')->width(4);
  28. $filter->like('name', 'Company Name')->width(4);
  29. });
  30. $grid->model()->where('enabled', 1);
  31. });
  32. }
  33. }