Okipa / laravel-table

Generate tables from Eloquent models.
MIT License
532 stars 64 forks source link

Multiple 'rowsConditionalClasses' entries don't work #66

Closed PaulMcRoar closed 3 years ago

PaulMcRoar commented 3 years ago

Hi,

If you want, for example, to check a set of statuses for a model and add a css class to the row accordingly, using repeated calls to 'rowsConditionalClasses' doesn't work, and I think it's supposed to.

The addClassesToRow method of HasClasses blitzes the $model->conditionnal_classes array if the closure returns a false value, and will empty the array. I think it should really be merging the $row['classes'] into the $model->conditionnal_classes array

Propose changing to

protected function addClassesToRow(Model $model): void
{
    $model->conditionnal_classes = [];
    $this->getRowsConditionalClasses()->each(
        fn($row) => ($row['closure'])($model) ? $model->conditionnal_classes = array_merge($model->conditionnal_classes,$row['classes']) : null
    );
}

I'm going to fork this project and add this in (as i need this working now), and I'll do a pull request.

Okipa commented 3 years ago

Hi @PaulMcRoar, thanks for reporting this !

This has been fixed in https://github.com/Okipa/laravel-table/pull/69.