$grid->actions(function ($actions) {
// 去掉查看
$actions->disableView();
});
//去掉复选框
$grid->disableRowSelector();
//禁用行操作
$grid->disableActions();
//禁用单选框
$grid->disableRowSelector();
//禁用新增按钮
$grid->disableCreation();
$grid->actions(function ($actions) {
//关闭行操作 删除
$actions->disableDelete();
});
//关闭批量操作
$grid->tools(function ($tools) {
$tools->batch(function ($batch) {
$batch->disableDelete();
});
});
$form
//表单bottom
$form->disableReset();
$form->disableEditingCheck();
$form->disableViewCheck();
//表单右上角
$form->tools(function (Form\Tools $tools) {
$tools->disableDelete();
$tools->disableView();
});
$grid
// 表单右上角
$grid->disableExport();
$grid->disableCreation();
//操作按钮
$grid->actions(function (Grid\Displayers\Actions $actions) {
$actions->disableDelete();
$actions->disableEdit();
$resDemand = Demand::find($actions->getKey());
$edit_html='';
//通过
if($resDemand->status==1){
$edit_html.="<span class='mb-5'><a class='grid-row-pass' title='审核' data-id='{$actions->getKey()}'><i class='glyphicon glyphicon-ok'></i></a></span>";
}
$actions->append($edit_html);
});
//批量操作
$grid->tools(function (Grid\Tools $tools) {
$tools->batch(function (Grid\Tools\BatchActions $actions) {
$actions->disableDelete();
});
});
$show
//表单右上角
$show->panel()->tools(function ($tools){
$tools->disableDelete();
$tools->disableEdit();
});
//可以通过传入的$actions参数来获取当前行的数据:
$grid->actions(function ($actions) {
// 当前行的数据数组
$actions->row;
// 获取当前行主键值
$actions->getKey();
});
如果有自定义的操作按钮,可以通过下面的方式添加
$grid->actions(function ($actions) {
// append一个操作
$actions->append('<a href=""><i class="fa fa-eye"></i></a>');
// prepend一个操作
$actions->prepend('<a href=""><i class="fa fa-paper-plane"></i></a>');
}
如果有比较复杂的操作,可以参考下面的方式:
先定义操作类
namespace App\Admin\Extensions;
use Encore\Admin\Admin;
class CheckRow
{
protected $id;
public function __construct($id)
{
$this->id = $id;
}
protected function script()
{
return <<<SCRIPT
$('.grid-check-row').on('click', function () {
// Your code.
console.log($(this).data('id'));
});
SCRIPT;
}
protected function render()
{
Admin::script($this->script());
return "<a class='btn btn-xs btn-success fa fa-check grid-check-row' data-id='{$this->id}'></a>";
}
public function __toString()
{
return $this->render();
}
}
然后添加操作:
$grid->actions(function ($actions) {
// 添加操作
$actions->append(new CheckRow($actions->getKey()));
});