orchidsoftware / platform

Orchid is a @laravel package that allows for rapid application development of back-office applications, admin/user panels, and dashboards.
https://orchid.software
MIT License
4.43k stars 651 forks source link

Add multiple info rows (more than one totals row) to the table #2358

Open Edinburgher opened 2 years ago

Edinburgher commented 2 years ago

Is your feature request related to a problem? Please describe. We now have a working row with totals for the Table layout. As explained in #1205:

The obvious disadvantage of this approach is the impossibility of specifying several lines at once. This can be a problem in the indication of any invoices when it is necessary to show tax and price in separate lines.

Describe the solution you'd like I propose an additional method infoRows. Each element of the returned array is a row represented by an array (could be replaced by a TR class that acts as a container) of TD cells. Similar as in #1205 I propose to ignore the "target" property for them.

protected function infoRows(): array
{
    return [
        [
            TD::make()
                ->align(TD::ALIGN_RIGHT)
                ->colspan(3)
                ->render(function () {
                    return __('Tax') . ':';
                }),
            TD::make('tax')
                ->colspan(2),
        ],
        [
            TD::make()
                ->align(TD::ALIGN_RIGHT)
                ->colspan(3)
                ->render(function () {
                    return __('Discount') . ':';
                }),
            TD::make('discount')
                ->colspan(2),
        ],
        [
            TD::make()
                ->canSee(false)
                ->align(TD::ALIGN_RIGHT)
                ->colspan(3)
                ->render(function () {
                    return __('Total') . ':';
                }),
            TD::make('total')
                ->colspan(2),
        ],
    ];
}

Additional context This also should not break compatibility. A possible solution is the following:

In table.blade.php

@if($infoRows->isNotEmpty())
    @foreach($infoRows as $infoRow)
        <tr>
            @foreach($infoRow as $column)
                {!! $column->buildTd($repository, $loop) !!}
            @endforeach
        </tr>
    @endforeach
@endif

In the Table class, method build:

$infoRows = collect($this->infoRows())->map(static function ($row) {
    return collect($row)->filter(static function (TD $column) {
        return $column->isSee();
    });
});

...

return view($this->template, [
...
    'infoRows' => $infoRows,
...
];
tabuna commented 2 years ago

I think we could do it right in the total method. Just allow the transfer of nesting and get as in your example. I just don't think it's cool to have two very similar methods, rather more confusing to use.