F
Filamentβ€’3mo ago
Uya

Need Help, How to use Count Summarize

So i have table like this
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('date_register')->label('Bulan')->date('l, jS F Y'),
Tables\Columns\TextColumn::make('type')->label('Jumlah')->summarize(
Count::make()->query(fn (Database\Query\Builder $query) => $query->groupBy('type'))->label('')
),
])
->filters([
//
])
->actions([
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
])
->defaultGroup(
// Group the rows by Year and Month (2023-09, 2023-11 etc) instead of "date"
Group::make('date_register')
// Ex: "2023-10-0",
// Note: You need the "-0" at the end, so Carbon can parse the date.
->getKeyFromRecordUsing(
fn(RegistrationData $record): string => $record->date_register
)

// Ex: "September 2023"
->getTitleFromRecordUsing(
fn(RegistrationData $record): string => $record->date_register->format('F Y')
)

// Set the default ordering
->orderQueryUsing(
fn(Builder $query, string $direction) => $query->orderBy('date_register', 'asc')
)
// Hide "date: " in the Group title
->titlePrefixedWithLabel(false)
->collapsible(),
);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('date_register')->label('Bulan')->date('l, jS F Y'),
Tables\Columns\TextColumn::make('type')->label('Jumlah')->summarize(
Count::make()->query(fn (Database\Query\Builder $query) => $query->groupBy('type'))->label('')
),
])
->filters([
//
])
->actions([
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
])
->defaultGroup(
// Group the rows by Year and Month (2023-09, 2023-11 etc) instead of "date"
Group::make('date_register')
// Ex: "2023-10-0",
// Note: You need the "-0" at the end, so Carbon can parse the date.
->getKeyFromRecordUsing(
fn(RegistrationData $record): string => $record->date_register
)

// Ex: "September 2023"
->getTitleFromRecordUsing(
fn(RegistrationData $record): string => $record->date_register->format('F Y')
)

// Set the default ordering
->orderQueryUsing(
fn(Builder $query, string $direction) => $query->orderBy('date_register', 'asc')
)
// Hide "date: " in the Group title
->titlePrefixedWithLabel(false)
->collapsible(),
);
}
and the result like the image, I think the summary that each group by date is not appropriate, how can I solve it?
No description
4 Replies
ChesterS
ChesterSβ€’3mo ago
What exactly are you trying to show here? The number of rows in each group?
Uya
UyaOPβ€’3mo ago
i want to show count for each group by month and year but in filament just group by date
ChesterS
ChesterSβ€’3mo ago
If you're only showing the number of rows in each group, you don't need the query part
->summarize(Count::make())
->summarize(Count::make())
should be enough. So something like
Tables\Columns\TextColumn::make('type')->label('Jumlah')->summarize(
Count::make()->label('')
),
Tables\Columns\TextColumn::make('type')->label('Jumlah')->summarize(
Count::make()->label('')
),
if you don't want to group by date, that's a different question. Also
Ex: "2023-10-0",
πŸ˜‚
Uya
UyaOPβ€’3mo ago
i see, thanks for the answer πŸ‘
Want results from more Discord servers?
Add your server