<?php
namespace App\Admin\Renderable;

use App\Models\DistAdminDistributor;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;

class DistDistributorTable extends LazyRenderable
{
    public function grid(): Grid
    {

        return Grid::make(new DistAdminDistributor(), function (Grid $grid) {
            $grid->column('id');
            $grid->column('company_name', 'Company Name');
            $grid->column('country', 'Country');
            $grid->column('site_name', 'Site Name');
            $grid->column('level_domain', 'Level Domain');
            $grid->column('created_at');
            $grid->column('updated_at');

            // 指定行选择器选中时显示的值的字段名称
            // 指定行选择器选中时显示的值的字段名称
            // 指定行选择器选中时显示的值的字段名称
            // 如果表格数据中带有 “name”、“title”或“username”字段，则可以不用设置
            $grid->rowSelector()->titleColumn('company_name');

            $grid->quickSearch(['id', 'company_name', 'level_domain']);

            $grid->paginate(10);
            $grid->disableActions();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->like('company_name')->width(4);
                $filter->like('level_domain', 'Level Domain')->width(4);
            });
            $grid->model()->where('enabled', 1);
        });
    }
}
