Power-Components / livewire-powergrid

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

[6.x] showToggleColumns() only hides row data but not header data #1716

Open nilios opened 4 days ago

nilios commented 4 days 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?

No, this error is not related to views.

Is there an error in the console?

no errors are reported

PHP Version

8.3

PowerGrid

6.0

Laravel

11.26

Livewire

3.5.9

Alpine JS

3.14.1

Theme

Tailwind 3.x with tailwind/forms

Describe the bug.

When enabling showToggleColumns, then viewing the table and clicking an item to hide it or show it, the data rows will shift to the left but the header row never disappears causing the data in the body rows (data rows) to shift left underneath a different column. After experimenting around a bit a possible fix seems to be applying a conditional check in the tr.blade.php when iterating columns checking for a false on the hidden column: @if(!data_get($column, 'hidden')) I haven't experimented much further than this, but this seems to solve at least my specific issue, however with other table configurations this may need to be applied elsewhere. Also, I have seen that with certain setups when hiding data the data in the table will not hide or show at all (neither body nor header). This can be observed on your demo dish page https://demo.livewire-powergrid.com/examples/demo-dish

To Reproduce...

enable showToggleColumns, view the table, click any item to show/hide an item and the data row will hide but the header will stay put. this functionality can be seen also on your demo page here https://demo.livewire-powergrid.com/examples/custom-field-image -- just hide any column and the data will shift left leaving the header still visible

Extra information

<?php
 //...
nilios commented 1 day ago

In working on a different issue (actions buttons not showing on tables) I discovered something. My tables use $primaryKey and a $sortField in them. If I remove these variables the action buttons show up and work as expected and the toggle columns issue is resolved as well. So apparently the bug is related to these properties and not directly to the toggle columns nor action buttons directly.

On a similar point, if you set route() on a button it doesn't convert it into a link but remains a button. If I add $this->tag = 'a'; to line 201 of Macros.php it seems to work. I hope this helps.