F
Filament9mo ago
Mio

TextColumn action not working as expected

Tables\Columns\TextColumn::make('title')
->action(function (Tables\Columns\TextColumn $column){
$column->description('Test');
})
Tables\Columns\TextColumn::make('title')
->action(function (Tables\Columns\TextColumn $column){
$column->description('Test');
})
This code should set the column description after clicked on the title text but it will set the 'Test' description for all title columns together
Tables\Columns\TextColumn::make('title')
->action(function (Tables\Columns\TextColumn $column, $record){
# record id is 123
$column->description($record->id);
})
Tables\Columns\TextColumn::make('title')
->action(function (Tables\Columns\TextColumn $column, $record){
# record id is 123
$column->description($record->id);
})
This code will set "123" as the description for all title columns if I try to change the clicked column state using the action method it will set all title columns together to same state
21 Replies
Mio
MioOP8mo ago
Can anybody help me please?
LeandroFerreira
LeandroFerreira8mo ago
Do you mean all rows, right? I think you could use a description column in your model to achieve what you need
->description(fn(Model $record): string => $record->description)
->action(function (Model $record) {
$record->update(['description' => 'new description']);
})
->description(fn(Model $record): string => $record->description)
->action(function (Model $record) {
$record->update(['description' => 'new description']);
})
Mio
MioOP8mo ago
Yes, after click on the title to active action and set the description only for that column the description set for all rows! I just want to show the description for one specific column only after I clicked on it Thanks for the reply ⬆️
awcodes
awcodes8mo ago
What are you actually trying to do? Why does a column need to show or hide a description on click? Just seems an odd use case to me.
Mio
MioOP8mo ago
I have a text column that I want to display the translated text when clicked, with the translated content sourced from database or an API. Just trying to show the translated text in the description
awcodes
awcodes8mo ago
Right but why does the description need to be based on a click, vs just showing it? Seems like a needless step.
dissto
dissto8mo ago
Uniformity i suppose 😋
awcodes
awcodes8mo ago
Well, just showing the description would be more uniform to me.
dissto
dissto8mo ago
one description has 5 paragraphs, the next 0, the next 12, the next 4, the next 5 etc. I would prefer uniformity too. I guess you could limit them all by default and on click reveal it 😊
awcodes
awcodes8mo ago
Why make the user click when it could just be shown if it exists.?
Mio
MioOP8mo ago
Because I don't need all columns to display the translated text, loading all of them together would result in excessive requests to the API
awcodes
awcodes8mo ago
Why? The data is what it is. The language should only matter to the app’s locale. If the app locale is en then why do you need to show table data in a different locale relative to the user.
Mio
MioOP8mo ago
The texts are in all languages and some of them need to translate to english in realtime it's not based on the app local
awcodes
awcodes8mo ago
But that doesn’t make sense. If the user is logged in as en then the data should be in en.
Mio
MioOP8mo ago
It's only for admin panel not users it's more than 2M data 😅
awcodes
awcodes8mo ago
Right but, what does admin have to do with the locale of the logged in user. I’m an admin who speaks Spanish, then I should see everything in Spanish. I’m an admin in English I should see everything in English. I think you might be missing the underlying point of i18n And I could be completely wrong, but it feels like a disconnect to me for the UI
Mio
MioOP8mo ago
Right but I just need some of the data to translate using the external API there is no need for me to translate all at once 😁
awcodes
awcodes8mo ago
But that’s exactly how i18n works.
Mio
MioOP8mo ago
beside this why the code doesn't work? it's a simple code am I missing something?
awcodes
awcodes8mo ago
It doesn’t work because you’re not compensating the app locale to the logged in user or you don’t have a middleware in place to reset it. This is a laravel concern and not necessarily related to filament.
Mio
MioOP8mo ago
no I mean this code it's not about localization or translation Just want to show the description for the column I clicked on it but it set 'Test' as description for all rows columns
Tables\Columns\TextColumn::make('title')
->action(function (Tables\Columns\TextColumn $column){
$column->description('Test');
})
Tables\Columns\TextColumn::make('title')
->action(function (Tables\Columns\TextColumn $column){
$column->description('Test');
})
Want results from more Discord servers?
Add your server