Arlind Musliu
Arlind Musliu
FFilament
Created by Arlind Musliu on 1/5/2024 in #❓┊help
Group by date and summarize number of pages
I found a solution for my issue: The problem when grouping is that Filament expects an ID column when displaying the data in a table. However, as we know, when we group rows according to a particular field, we don't need the ID of a row. To fix this, we need to create a new field ID that will be formed by the number of total grouped roles. That can be done through SQL like this:
return $table->query(
Reading::query()
->groupByRaw('DATE_FORMAT(date, "%Y-%m")')
->selectRaw('ROW_NUMBER() OVER (ORDER BY DATE_FORMAT(date, "%Y-%m")) AS id')
->selectRaw('DATE_FORMAT(date, "%Y-%m") as date, SUM(pages) as pages')
->orderBy('date', 'desc')
->where('user_id', auth()->user()->id)
->limit(10)
)
->columns([
Tables\Columns\TextColumn::make('date')
->label('Month')
->date('M Y'),
Tables\Columns\TextColumn::make('pages')
->label('Pages Read'),
])
->groupsOnly();
return $table->query(
Reading::query()
->groupByRaw('DATE_FORMAT(date, "%Y-%m")')
->selectRaw('ROW_NUMBER() OVER (ORDER BY DATE_FORMAT(date, "%Y-%m")) AS id')
->selectRaw('DATE_FORMAT(date, "%Y-%m") as date, SUM(pages) as pages')
->orderBy('date', 'desc')
->where('user_id', auth()->user()->id)
->limit(10)
)
->columns([
Tables\Columns\TextColumn::make('date')
->label('Month')
->date('M Y'),
Tables\Columns\TextColumn::make('pages')
->label('Pages Read'),
])
->groupsOnly();
2 replies
FFilament
Created by Oleksandr on 8/7/2023 in #❓┊help
Error When Displaying Aggregated Data in Filament Resource Table
I found a solution for my issue: The problem when grouping is that Filament expects an ID column when displaying the data in a table. However, as we know, when we group rows according to a particular field, we don't need the ID of a row. To fix this, we need to create a new field ID that will be formed by the number of total grouped roles. That can be done through SQL like this:
->where('dt', '>=', $today)
->groupByRaw('DATE_FORMAT(dt, "%H:00")')
->selectRaw('ROW_NUMBER() OVER (ORDER BY hour) AS id')
->selectRaw('DATE_FORMAT(dt, "%H:00") as hour, SUM(rounded) as total_sum');
->where('dt', '>=', $today)
->groupByRaw('DATE_FORMAT(dt, "%H:00")')
->selectRaw('ROW_NUMBER() OVER (ORDER BY hour) AS id')
->selectRaw('DATE_FORMAT(dt, "%H:00") as hour, SUM(rounded) as total_sum');
I have modified my code to adapt it to your need, but you'll have to test it.
5 replies
FFilament
Created by Apollos on 12/15/2023 in #❓┊help
Syntax error or access violation: 1055 Expression #1 of ORDER BY clause is not in GROUP BY
I found a solution for my issue: The problem when grouping is that Filament expects an ID column when displaying the data in a table. However, as we know, when we group rows according to a particular field, we don't need the ID of a row. To fix this, we need to create a new field ID that will be formed by the number of total grouped roles. That can be done through SQL like this:
->groupByRaw('agent_name')
->selectRaw('ROW_NUMBER() OVER (ORDER BY agent_name) AS id')
->selectRaw('agent_name as name')
->groupByRaw('agent_name')
->selectRaw('ROW_NUMBER() OVER (ORDER BY agent_name) AS id')
->selectRaw('agent_name as name')
I have modified my code to adapt it to your need, but you'll have to test it.
3 replies
FFilament
Created by Apollos on 12/15/2023 in #❓┊help
Syntax error or access violation: 1055 Expression #1 of ORDER BY clause is not in GROUP BY
Hey @Apollos , did you manage to find a solution for this? I have the same problem
3 replies
FFilament
Created by Oleksandr on 8/7/2023 in #❓┊help
Error When Displaying Aggregated Data in Filament Resource Table
Hey @Oleksandr , did you manage to fix this? I have the same problem and error 😅
5 replies