Table with Records (no Query) crashes while using summarize

Im using a table with static records and want to show a sum at the end of the table with the summarize method. Here is my code:
return $table
->records(fn (self $livewire) => $livewire->data)
->selectable()
->columns([
TextColumn::make('name'),
TextColumn::make('amount')
->label('Betrag')
->money()
->color('primary')
->summarize(Sum::make()),
])
return $table
->records(fn (self $livewire) => $livewire->data)
->selectable()
->columns([
TextColumn::make('name'),
TextColumn::make('amount')
->label('Betrag')
->money()
->color('primary')
->summarize(Sum::make()),
])
Here the error i get: getTableSummarySelectedState(): Argument #1 ($query) must be of type Illuminate\Database\Eloquent\Builder, null given The function needs a query instance to work but apparently there is none:
/**
* @return array<string, mixed>
*/
public function getTableSummarySelectedState(Builder $query, ?Closure $modifyQueryUsing = null): array
/**
* @return array<string, mixed>
*/
public function getTableSummarySelectedState(Builder $query, ?Closure $modifyQueryUsing = null): array
Solution:
GitHub
[4.x] Table summarize with custom data · Issue #17286 · filamentp...
Package filament/filament Package Version v4.0.0 Laravel Version v12.23.1 Livewire Version v3.0.0 PHP Version PHP 8.4.11 Problem description When declaring a table either through the Widget menu or...
Jump to solution
8 Replies
muesker
mueskerOP2w ago
Kind of a fix to give the table an empty query...it works but there should be a better way.
Dennis Koch
Dennis Koch2w ago
How do you summarise static data? Last time I looked it was not supported.
muesker
mueskerOP2w ago
Oh okay i didnt know it was not supported thats good to know because i thought its just a bug or a scenario nobody thought about. Everybody should know that my "fix" is nowhere best practice but it works for me for now. Maybe in the future when i have time i could try to make a pr but right now i dont have the time.
return $table
->query(MnxEvent::query())
->records(fn (self $livewire) => $livewire->data)
->selectable()
->currentSelectionLivewireProperty('selectedEventAdvances')
->liveEntangleSelection() // this is my own patch to get live updates on select
->columns([
TextColumn::make('name'),
TextColumn::make('amount')
->label('Abschlagsbetrag')
->money()
->color('primary')
->summarize(Summarizer::make('sum')
->money()
->using(function (self $livewire) {
return collect($livewire->data)->filter(fn ($item) => in_array($item['id'], $livewire->selectedEventAdvances))->sum('amount');
})
),
])
return $table
->query(MnxEvent::query())
->records(fn (self $livewire) => $livewire->data)
->selectable()
->currentSelectionLivewireProperty('selectedEventAdvances')
->liveEntangleSelection() // this is my own patch to get live updates on select
->columns([
TextColumn::make('name'),
TextColumn::make('amount')
->label('Abschlagsbetrag')
->money()
->color('primary')
->summarize(Summarizer::make('sum')
->money()
->using(function (self $livewire) {
return collect($livewire->data)->filter(fn ($item) => in_array($item['id'], $livewire->selectedEventAdvances))->sum('amount');
})
),
])
You can also see ive implemented my own "liveEntangleSelection" with a quick composer patch. That functionality would be nice in the future aswell (maybe another pr of me when i got time). I use the live entanglement to show a sum for all selected entries which was an requirement of our customer.
Dennis Koch
Dennis Koch2w ago
I thought all those summarizers work on the DB level, so I'm surprised you got some results. Might be wrong though. @Dan Harrin I don't think we support summarisers on custom data (at least we don't mention it in the docs), but looks like it's not too hard to add with custom Summarizers. Should this work?
Dan Harrin
Dan Harrin2w ago
have you checked if theres an issue open for it
Dennis Koch
Dennis Koch2w ago
Nope, I considered this as "not supported" for now, so I didn't look for bugs 😅
Solution
Dennis Koch
Dennis Koch2w ago
GitHub
[4.x] Table summarize with custom data · Issue #17286 · filamentp...
Package filament/filament Package Version v4.0.0 Laravel Version v12.23.1 Livewire Version v3.0.0 PHP Version PHP 8.4.11 Problem description When declaring a table either through the Widget menu or...
muesker
mueskerOP2w ago
Ah i missed that ticket - sorry FYI: my empty query i added is not running at all so its just there to fix the error I will drop my quick fix in there for now so people can use it for now

Did you find this page helpful?