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

[FIX] summarizeFormat() - Format leaking across columns #1530

Closed dansysanalyst closed 2 months ago

dansysanalyst commented 2 months ago

⚡ PowerGrid - Pull Request

Welcome and thank you for your interest in contributing to our project!. You must use this template to submit a Pull Request or it will not be accepted.


Motivation

Description

This Pull Request fixes the bug described in the issue, which prevents applying a different Summary method formatting in each column.

    public function summarizeFormat(): array
    {
        return [
            'price.{sum,avg,min,max}' => fn ($value) => Number::currency($value, in: 'USD'),
            'price.{count}'    => fn ($value) => Number::format($value, locale: 'br') . ' price(s)',
            'calories.{avg}'   => fn ($value) => Number::format($value, locale: 'br', precision: 2) . ' kcal',
        ];
    }

Result:

CleanShot 2024-05-06 at 01 04 26@2x


In addition, from now on PowerGrid will throw an exception if the user does not follow the syntax column_name.{summarize_method} or does not send a callable in summarizeFormat().

Related Issue(s): https://github.com/Power-Components/livewire-powergrid/issues/1529.

Documentation

This PR requires Documentation update?

luanfreitasdev commented 2 months ago

Thank you Dan!