Table styles

You're browsing the documentation for an old version of MoonShine. Consider upgrading your project to MoonShine 2.x.

Using resources you can customize the color for tr and td for tables with data

namespace MoonShine\Resources;
 
class PostResource extends Resource
{
public static string $model = App\Models\Post::class;
 
public static string $title = 'Articles';
//...
 
public function trClass(Model $item, int $index): string
{
if($item->id === 1 || $index === 2) {
return 'green';
}
 
return parent::trClass($item, $index);
}
 
public function tdClass(Model $item, int $index, int $cell): string
{
if($cell === 6) {
return 'red';
}
 
return parent::tdClass($item, $index, $cell);
}
//...
}

Available colors:

Purple Pink Blue Green Yellow Red Gray

You can also add custom styles

namespace MoonShine\Resources;
 
class PostResource extends Resource
{
public static string $model = App\Models\Post::class;
 
public static string $title = 'Articles';
//...
 
public function trStyles(Model $item, int $index): string
{
if ($item->id === 1 || $index === 2) {
return 'background: rgba(128, 152, 253, .5);';
}
 
return parent::trStyles($item, $index);
}
 
public function tdStyles(Model $item, int $index, int $cell): string
{
if ($cell === 3) {
return 'background: rgba(128, 253, 163, .5); text-align:center;';
}
 
return parent::tdStyles($item, $index, $cell);
}
//...
}