F
Filament8mo ago
terumi

Persist toggleable column state between sessions

Hello, It is a way to persist the toggled state of a column? Some of my users want to see their data by default deferently from others but I cannot find a way to persist their table. Is it possible?
9 Replies
terumi
terumi8mo ago
No: I have a table with these data: name | surname | created_at | updated_at some users want to see only name | created_at others want to see: name | surname | updated_at etc... Each user can set it via the icon on the right of the table, but as soon as, they loggout they have to set it again. Is there a way to persist their choice?
mariusticha
mariusticha8mo ago
alright now i understand what your looking for. i've done a little research on this and i haven't found a built in functionality for this use case. what i've found is the part in the app where the visible columns are determined. that should be this method here: https://github.com/filamentphp/filament/blob/3.x/packages/tables/src/Table/Concerns/HasColumns.php#L101
GitHub
filament/packages/tables/src/Table/Concerns/HasColumns.php at 3.x ·...
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS. - filamentphp/filament
mariusticha
mariusticha8mo ago
maybe this will help you a little
Kenneth Sese
Kenneth Sese8mo ago
Self promotion, but my plugin #kenneth-sese-advanced-tables does exactly this...let your users create whatever custom views they want. Filters, columns, reorderable columns, etc.
Mark Chaney
Mark Chaney7mo ago
I hate to reopenin this, but are toggle-able states really not persistent unless using hidden by default? Seems like a frustrating experience if a user hides columns and then any refresh brings them back.
Kenneth Sese
Kenneth Sese7mo ago
Toggled columns persist in session so refreshing is fine. The OP was referring to persisting through logout, which clears the session.
Mark Chaney
Mark Chaney7mo ago
Hmm, mine aren’t persisting on refresh. Will open a separate thread for that
Umar Farooq
Umar Farooq3mo ago
any update? is there a way to get the state of the toggleable column state so I can save it in the cache? Only solution I found
/**
* @return void
*/
public function updatedToggledTableColumns(): void
{
Cache::forever('user-toggle-' . $this->record->id, $this->toggledTableColumns);

session()->put([
$this->getTableColumnToggleFormStateSessionKey() => $this->toggledTableColumns,
]);
}
/**
* @return void
*/
public function updatedToggledTableColumns(): void
{
Cache::forever('user-toggle-' . $this->record->id, $this->toggledTableColumns);

session()->put([
$this->getTableColumnToggleFormStateSessionKey() => $this->toggledTableColumns,
]);
}
then
->toggleable(isToggledHiddenByDefault: function () {
$toggleState = Cache::get('user-toggle-' . $this->record->id);

if ($toggleState) {
return !$toggleState['full_name'];
}

return false;
})
->toggleable(isToggledHiddenByDefault: function () {
$toggleState = Cache::get('user-toggle-' . $this->record->id);

if ($toggleState) {
return !$toggleState['full_name'];
}

return false;
})