Power-Components / livewire-powergrid

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

hidden() with visibleInExport(true) not working #165

Closed wturrell closed 2 years ago

wturrell commented 2 years ago

There's a simple reason for this, but I'm not totally confident how you fix it without breaking things for existing users…

As per the docs, I'm trying to get "a column to appear in the file but not at the web-page", by setting both hidden() and visibleInExport(true).

This doesn't work, because of the conditional below - it'll only include columns in the export which are ! hidden.

Solution?

In https://github.com/Power-Components/livewire-powergrid/blob/main/src/Services/Export.php#L54

you've got:

if (!$column->hidden && $column->visibleInExport) {

It feels like it ought to only check $column->visibleInExport, because 'hidden' shouldn't matter as this is the Export. Except if you do that, there will be a bunch of people with existing tables who've used hidden() by itself without knowing about / specifying visibleInExport, and suddenly they'll have a bunch of unwanted columns.

Maybe if (! hidden && visibleInExport) || visibleInExport) ?

If I were designing it from scratch I think I'd separate them: ->hiddenWeb() and ->hiddenExport(), but…

To Reproduce

            Column::add()
                ->title(__('Searches'))
                ->field('searches')
                ->hidden()
                ->visibleInExport(true),

Laravel 8.73.2
PHP 8.0 and 8.1
PowerGrid 1.5.0 (couldn't get it to work in 1.4.7 either)
Tailwind

luanfreitasdev commented 2 years ago

Thanks @wturrell for the suggestions.

At first the ->hidden method must hide the column in the web table and in the export. Maybe it's better to leave the hidden only in the Web part, it makes more sense

The only problem is that whenever it is hidden, visibleInExport (false)must be set so that it does not appear

LukaTarkhn commented 2 years ago

@luanfreitasdev @wturrell So we have a solution for this issue? issue closed but where is the solution?

luanfreitasdev commented 2 years ago

The mentioned solution doesn't seem to work, if you want to improve it, please open a PR and express your point of view

Stridesdata commented 2 years ago

@luanfreitasdev @wturrell So we have a solution for this issue? issue closed but where is the solution?

image