Power-Components / livewire-powergrid

⚡ PowerGrid generates modern, powerful and easy-to-customize data tables using Laravel Livewire.
https://livewire-powergrid.com
MIT License
1.41k stars 205 forks source link

[BUG] Formatting multiple columns with summarizeFormat() #1529

Closed dansysanalyst closed 2 months ago

dansysanalyst commented 2 months ago

Have you searched through other issues to see if your problem is already reported or has been fixed?

Yes, I did not find it.

Did you read the documentation?

Yes, I did not find it.

Have you tried to publish the views?

Yes - I didn't work.

Is there an error in the console?

No

PHP Version

No response

PowerGrid

No response

Laravel

No response

Livewire

No response

Alpine JS

No response

Theme

Tailwind 3.x

Describe the bug.

No response

To Reproduce...

I would like to format the average summary in two different columns, one as a kcal and the other as currency $.

Expected:

IMAGE 2024-05-05 11:06:47


Result:

IMAGE 2024-05-05 11:06:49

Extra information

Column::make('Calories', 'calories', 'calories')
                ->withAvg('Average', header: true, footer: false)
                ->sortable(),

Column::make('Price', 'price_formatted', 'price')
                ->withSum('Sum Price', header: true, footer: false)
                ->withAvg('Avg Price', header: true, footer: false)
public function summarizeFormat(): array
{
    return [
        'calories.{avg}'          => fn ($value) => Number::format($value, locale: 'br') . ' kcal',
        'price.{sum,avg,min,max}' => fn ($value) => Number::currency($value, in: 'USD'),
        'price.{count}'           => fn ($value) => Number::format($value, locale: 'br'),
    ];
}
dansysanalyst commented 2 months ago

I should be sending a PR soon fixing this issue.

dansysanalyst commented 2 months ago

Fixed in v5.6.0