[6.x] showToggleColumns() only hides row data but not header data
Closed this issue ยท 16 comments
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
//...
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.
I get same behavior by setting $primaryKey = 'master.id': action buttons not showing.
I found also that in the html, the wire:key="row--column_name-0" is missing the key between the first two dashes and a lot of deprecation warnings are logged.
View is generated from \livewire-powergrid\components\row.blade.php:
wire:key="row-{{ substr($rowId, 0, 6) }}-{{ $field }}-{{ $childIndex ?? 0 }}"
where i see there another problem, my ids can have more than 6 characters.
removing $primaryKey, everything works except export SQL fails with Column 'id' in where clause is ambiguous
[Related] livewire/livewire#8883
Hello
I checked and found that versions above 3.5.7 have this problem, you can add this to your composer
Forgive me for being a little confused. I don't think this is a livewire issue. As explained in my original post if I edit tr.blade.php and modify this section (line 49):
@foreach ($columns as $column)
<x-livewire-powergrid::cols
wire:key="cols-{{ data_get($column, 'field') }} }}"
:$column
:$theme
:$enabledFilters
/>
@endforeach
and change it to this:
@foreach ($columns as $column)
@if(!data_get($column, 'hidden'))
<x-livewire-powergrid::cols
wire:key="cols-{{ data_get($column, 'field') }} }}"
:$column
:$theme
:$enabledFilters
/>
@endif
@endforeach
then the toggle column functionality seems to work. It doesn't appear to impact anything else, but I'm not sure what this change may do with other enabled settings or configurations.
The only other thing is just the action buttons not showing up if $primaryKey is set on the table, but removing it allows the buttons to show. Is it this issue you are referring to as the livewire issue?
I don't think that's a livewire issue but instead the problem is with setting $primaryKey.
And I could not add code below in composer.json (i was already in v3.5.9):
"conflict": {
"livewire/livewire": "3.5.7 || 3.5.8 || 3.5.9"
},
because of: power-components/livewire-powergrid[v6.0.0, ..., v6.0.1] require livewire/livewire ^3.5.8
@nilios , I do not recommend doing this as it may cause other unknown issues. Try installing version 6.0.2 with livewire below 3.5.7
Screen.Recording.2024-10-10.at.14.46.44.mov
Try with 6.0.2
I tried with
livewire/livewire v3.5.6 A front-end framework for Laravel.
power-components/livewire-powergrid v6.0.2 PowerGrid generates Advanced Datatables using Laravel Livewire.
- deprecation log still flooded with local.WARNING: substr(): Passing null to parameter 1
- action buttons still not shown
it looks that the issue persists.
Thank you for your time!
@PekoKent, this problem has nothing to do with showToggleColumns, but with the actions. Could you open another issue with more details? If possible, could you create a simple example repository?
@luanfreitasdev Thank you, I tried it and seems to work. Hopefully this will limp by for a little while until the guys at livewire can get a fix out.
I believe this was fixed with Livewire version 3.5.10
Confirmed toggle columns is fixed with livewire 3.5.10. Thank you for helping with this issue and your quick responses. Loving the tables by the way, keep up the great work!
I updated to "livewire/livewire" version: "v3.5.10", and it works fine
name : livewire/livewire versions : * v3.5.12
name : power-components/livewire-powergrid versions : * v6.1.2
I have this problem again.