Dcat Admin 定义指定行样式,如背景颜色等。

admin 阅读:49 2024-03-02

使用 Dcat Admin 开发网站后台,需要自定义数据表格中部分数据行的背景颜色,官方文档中只有设置选中行的背景颜色方法:

$grid->rowSelector()->background(Admin::color()->dark20());

而我们的需求是定义指定行的颜色,看了下源码,解决方案如下:

$grid->rows(function (Collection $rows) {
	$rows->each(function ($item) {
		if ($item->score > 90) {
			$item->setAttributes(['style' => 'background:#20c997;color:white']);
		}
	});
});

效果:

声明

1、部分文章来源于网络,仅作为参考。
2、如果网站中图片和文字侵犯了您的版权,请联系1943759704@qq.com处理!

搜索