-
-
Notifications
You must be signed in to change notification settings - Fork 344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Column select #776
Column select #776
Conversation
These changes are backwards compatible, however we should consider the following:
|
I haven't tested yet but it looks good. Just curious, why add to query string instead of boot:
$this->{$this->tableName}` = [
'sorts' => $this->{$this->tableName}['sorts'] ?? [],
'filters' => $this->{$this->tableName}['filters'] ?? [],
'columns' => $this->{$this->tableName}['userSelectedColumns'] ?? [],
]; Or something like that, unless I'm missing something, but it's cleaner to me that its under the same table key in the URL and not its own global thing? |
I think it could be done that way yes. But with the fingerprint (and alias*) now the We also may have to check everywhere to make sure the array key // Set to either the default set or what is stored in the session
$this->selectedColumns = count($this->userSelectedColumns) > 0 ?
$this->userSelectedColumns :
session()->get($this->getColumnSelectSessionKey(), $columns); Becomes? // Set to either the default set or what is stored in the session
$this->selectedColumns = (isset($this->{$this->tableName}['userSelectedColumns']) && count($this->{$this->tableName}['userSelectedColumns']) > 0) ?
$this->{$this->tableName}['userSelectedColumns'] :
session()->get($this->getColumnSelectSessionKey(), $columns); *edit |
Of course I could be wrong here. I'll have to run some tests using the |
Ah, I see. Works like this: // Set to either the default set or what is stored in the session
$this->selectedColumns = count($this->{$this->tableName}['columns']) > 0 ?
$this->{$this->tableName}['columns'] :
session()->get($this->getColumnSelectSessionKey(), $columns); I'm going to push a change following your suggestion. It is a little better, I think. Edit: We can always simplify |
I mean i'm all for removing that syntax if it's backward compatible. |
@rappasoft done and tested. (phpunit as well as user story with two tables on same page). Please have a look when you get a chance. |
Don't have too much time to test but I'm getting some funky behavior when I deselect a column:
|
Ok thanks. I'll have a look when I get a chance. |
Ok so looks like I can replicate the error using the demo. Looks like there is indeed some strange behavior, specifically when the columns aren't actually database columns. The check boxes don't have a value, and the value put into the session is |
This was due to the use of |
Here's how it must have worked before: ➜ laravel-livewire-tables-demo git:(master) ✗ php artisan tinker
Psy Shell v0.11.4 (PHP 8.1.5 — cli) by Justin Hileman
>>> md5(null)
PHP Deprecated: md5(): Passing null to parameter #1 ($string) of type string is deprecated in laravel-livewire-tables-demoeval()'d code on line 1
=> "d41d8cd98f00b204e9800998ecf8427e"
>>> 🤔 |
@rappasoft due to the extensibility of working with the |
@Ceepster14 I think we can consider this branch pretty stable at this point. Is there any chance you could test this in your project and confirm that it close #760 before we merge it? composer require rappasoft/laravel-livewire-tables:column-select-dev |
Hi guys, Great work! I've given this fix a bit of a thrashing and it all seems to hold up. No more missing columns. Thanks for all your efforts! Chris |
unfortunately one part of this feature still isn't working properly: public function configure(): void
{
$this->setQueryStringAlias('users-table2'); // defaults to $tableName
} This indeed sets an alias, however on page refresh or a fresh visit it clears the query string. I thought that maybe it was because I hadn't added an actual public property to the Here is how the alias is set during configuration: public function setQueryStringAlias(string $queryStringAlias): self
{
$this->queryStringAlias = $queryStringAlias;
return $this;
} And here is how it is used in the query string: public function queryString(): array
{
if ($this->queryStringIsEnabled()) {
return [
$this->getTableName() => ['except' => null, 'as' => $this->getQueryStringAlias()],
];
}
return [];
} And here is the public function getQueryStringAlias(): string
{
return $this->queryStringAlias ?? $this->getTableName();
} So far I've tried adding public array $table = [];
public $theme = null;
+ public $queryStringAlias = null; But this doesn't seem work. Any ideas or help would be appreciated. Marking this as a draft for now. WIP |
Hmm ... Looks like it's back to the same problem as here livewire/livewire#4300. hard coding the alias works fine:
but trying to set it at runtime doesn't seem to work. |
This seems to have done the trick. Any reason we can't do this? /**
* Runs on every request, immediately after the component is instantiated, but before any other lifecycle methods are called
*/
public function boot(): void
{
$this->{$this->tableName} = [
'sorts' => $this->{$this->tableName}['sorts'] ?? [],
'filters' => $this->{$this->tableName}['filters'] ?? [],
'columns' => $this->{$this->tableName}['columns'] ?? [],
];
// Set the filter defaults based on the filter type
$this->setFilterDefaults();
+ $this->configure();
}
/**
* Runs on every request, after the component is mounted or hydrated, but before any update methods are called
*/
public function booted(): void
{
- $this->configure();
$this->setTheme();
$this->setBuilder($this->builder());
$this->setColumns();
// Make sure a primary key is set
if (! $this->hasPrimaryKey()) {
throw new DataTableConfigurationException('You must set a primary key using setPrimaryKey in the configure method.');
}
} |
Column selection should be disabled for multiple of same component. - It has never worked and the only way to make it work now would be to pass in some identifier at mount() and use that to change the fingerprint with `setDataTableFingerprint()`. - Due to the high potential for errors in setting arbitrary properties and manipulating them at mount(), then attempting to use them in configure(), I think it's best not to support this type of configuration in the docs, although IT CAN BE DONE. - There is a suggestion in the docs for reusing components on different pages which is less error prone.
This reverts commit 3a03091.
Does this PR fix this issue #760? |
Yes it does. And it should be good to go. I just wanted Anthony to look over it before merging it in. I'm sure he'll review the open PR's before the next release, and he releases often. He just got sick and things got a little backed up for him. Should be back soon. |
I look forward to the release of a new version to include this very important fix. :) |
This feature uniquely identifies each table for column selections stored in the session. It also allows for columns selections to be put into the query string, so that selections can be bookmarked.
The tldr; is that we now have a fingerprinting method that uses
static::class
to generate a key, or slug for each component, to be used as an alias for$tableName
in the session and query string arrays, which is always the same for the same component, and always different for another.This produces urls that look something like this:
http://table-demo.test/?11mbmzx[filters][year]=2022&11mbmzx-c[0]=year
Where
11mbmzx
is thefingerprint
, or uniquealias
for the component.The dynamic link above will apply a filter with the key of
year
and value2022
and select to only have theyear
column displayed.checking only the
year
column in the columns▼ dropdown on a table fingerprinted11mbmzx
will put11mbmzx-c[0]=year
into the query string. it will also put the following array into the session:11mbmzx-columnSelectEnabled
=> array:1 [▼0 =>
year
]
Query strings will be evaluated first to determined which columns should be displayed, after that the session, followed by the default.
closes #760