jqhph / dcat-admin

🔥 基于 Laravel 的后台系统构建工具 (Laravel Admin),使用很少的代码快速构建一个功能完善的高颜值后台系统,内置丰富的后台常用组件,开箱即用,让开发者告别冗杂的HTML代码
http://www.dcatadmin.com
MIT License
3.88k stars 709 forks source link

如何根据字段值动态设置列表中行的背景颜色? #826

Closed zhaoshl closed 3 years ago

zhaoshl commented 3 years ago

Description:

使用行选择器 (rowSelector)的 设置选中行的背景颜色 $grid->rowSelector()->background(Admin::color()->dark20()); 看不到效果

$grid->rowSelector()->circle(false);//报错:Call to undefined method Dcat\Admin\Grid\Tools\RowSelector::circle()

请问有没有其他解决方案?

Steps To Reproduce:

jqhph commented 3 years ago
$grid->rows(function (Grid\Row $row) {
    if ($row->id = 10) {
        $row->setAttributes(['style' => 'background: #ddd']);
    }
 });
zhaoshl commented 3 years ago
$grid->rows(function (Grid\Row $row) {
    if ($row->id = 10) {
        $row->setAttributes(['style' => 'background: #ddd']);
    }
 });

非常感谢! 测试了一下,报错: Argument 1 passed to App\Admin\Controllers\...Controller::App\Admin\Controllers\{closure}() must be an instance of Dcat\Admin\Grid\Row, instance of Illuminate\Support\Collection given, called in ...\vendor\dcat\laravel-admin\src\Grid.php on line 458 请教如何解决呢?

zhaoshl commented 3 years ago

补充一下自己的解决办法,不知道是不是最佳的方案

            $grid->rows(function (Collection $rows) {
                $rows = $rows->each(function ($item, $key) {
                    if ($item->flag) {
                        $item->setAttributes(['style' => 'background: #ddd']);
                    }
                });
            });
newbrash commented 3 years ago

补充一下自己的解决办法,不知道是不是最佳的方案

            $grid->rows(function (Collection $rows) {
                $rows = $rows->each(function ($item, $key) {
                    if ($item->flag) {
                        $item->setAttributes(['style' => 'background: #ddd']);
                    }
                });
            });

是不是群主新版本改了

newbrash commented 3 years ago

补充一下自己的解决办法,不知道是不是最佳的方案

            $grid->rows(function (Collection $rows) {
                $rows = $rows->each(function ($item, $key) {
                    if ($item->flag) {
                        $item->setAttributes(['style' => 'background: #ddd']);
                    }
                });
            });

看了下源代码,这就是最佳的方案了,感谢

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.