model-grid 默认有四个行操作编辑、快捷编辑、删除和详情,可以通过下面的方式关闭它们:
$grid->actions(function ($actions) {
$actions->disableDelete();
$actions->disableEdit();
$actions->disableQuickEdit();
$actions->disableView();
}
// 也可以通过以下方式启用或禁用按钮
$grid->disableDeleteButton();
$grid->disableEditButton();
$grid->disableQuickEditButton();
$grid->disableViewButton();
//去掉复选框
$grid->disableRowSelector();
//禁用行操作 去掉行 操作
$grid->disableActions();
//禁用新增按钮
$grid->disableCreation();
//关闭批量操作
$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);
});
$show
//表单右上角
$show->panel()->tools(function ($tools){
$tools->disableDelete();
$tools->disableEdit();
});
获取当前行数据
use Dcat\Admin\Grid;
$grid->actions(function (Grid\Displayers\Actions $actions) {
// 当前行的数据数组
$rowArray = $actions->row->toArray();
// 当前行的某个字段的数据
$email = $actions->row->email;
// 获取当前行主键值
$id = $actions->getKey();
});
添加自定义按钮
use Dcat\Admin\Grid;
$grid->actions(function (Grid\Displayers\Actions $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>');
}
添加复杂操作按钮
php artisan admin:action
<?php
namespace App\Admin\Extensions;
use Dcat\Admin\Grid\RowAction;
class CheckRow extends RowAction
{
/**
* 返回字段标题
*
* @return string
*/
public function title()
{
return 'Check row';
}
/**
* 添加JS
*
* @return string
*/
protected function script()
{
return <<<JS
$('.grid-check-row').on('click', function () {
// Your code.
console.log($(this).data('id'));
});
JS;
}
public function html()
{
// 获取当前行数据ID
$id = $this->getKey();
// 获取当前行数据的用户名
$username = $this->row->username;
// 这里需要添加一个class, 和上面script方法对应
$this->setHtmlAttribute(['data-id' => $id, 'email' => $username, 'class' => 'grid-check-row']);
return parent::html();
}
}
然后添加操作:
$grid->actions(new CheckRow());
// 也可以通过这种方式添加
$grid->actions(function (Grid\Displayers\Actions $actions) {
$actions->append(new CheckRow());
}
https://learnku.com/docs/dcat-admin/2.x/use-and-extension-of-rows/8092