display count matching getTableRecordClassesUsing

I have a component displaying a table and it's highlighting certain rows using the getTableRecordClassesUsing() function. The blade file is pretty simple as it just returns the table. However, I'd like to have the count of rows matching the getTableRecordClassesUsing() available in this blade file as I'd like to do some other blade logic based on that value. I tried saving the count in a variable, but it doesn't get updated below the table after the user edits a record making it no longer match the getTableRecordClassesUsing() function. Any help would be greatly appreciated.
<div>
{{ $this->table }}
</div>

Count matching CSS rule: {{ $this->records_match }}
<div>
{{ $this->table }}
</div>

Count matching CSS rule: {{ $this->records_match }}
Solution:
I have a component displaying a table and it's highlighting certain rows using the getTableRecordClassesUsing() function. The blade file is pretty simple as it just returns the table. However, I'd like to have the count of rows matching the getTableRecordClassesUsing() available in this blade file as I'd like to do some other blade logic based on that value. I tried saving the count in a variable, but it doesn't get updated below the table after the user edits a record making it no longer match the getTableRecordClassesUsing() function. Any help would be greatly appreciated. ```php...
Jump to solution
2 Replies
Patrick Boivin
Can you share your getTableRecordClassesUsing() method, to have a better idea of what's happening?
usmcgator
usmcgatorOP2y ago
Here's the solution. In this scenario, it looks for the value from the assessment column for that record and if its value is null, highlight the row with as priority (dark:border.etc if dark mode). If it's not null style it based on the value in the mission column. I then have different styles for each mission value that could exist.
protected function getTableRecordClassesUsing(): ?Closure
{
return fn (Model $record) => match ($record->assessment) {
null => [
'priority',
'dark:border-orange-300' => config('tables.dark_mode'),
],
default => $record->mission,
};
}
protected function getTableRecordClassesUsing(): ?Closure
{
return fn (Model $record) => match ($record->assessment) {
null => [
'priority',
'dark:border-orange-300' => config('tables.dark_mode'),
],
default => $record->mission,
};
}
Want results from more Discord servers?
Add your server