F
Filamentβ€’2y ago
Atena.D

Get other column value, filament tables

Hi. How can I get another column value in ->default() method in filament tables?
22 Replies
toeknee
toekneeβ€’2y ago
Is this on load from the record, or is this when a change occurs
Atena.D
Atena.DOPβ€’2y ago
I just want to use that as the default value of another column. how can I get that in ->default() method? should I use closure ?
Dennis Koch
Dennis Kochβ€’2y ago
fn ($record) => $record->field
Atena.D
Atena.DOPβ€’2y ago
this didn't work for me
toeknee
toekneeβ€’2y ago
you need a closure with Dennis approach, but remember default will only be used if the value is truly empty. If using fill, you will need to add it to the fill method too. Defaults are designed for new forms
Dennis Koch
Dennis Kochβ€’2y ago
Do TableColumns even have defaults? πŸ€”
toeknee
toekneeβ€’2y ago
I assumed it was forms doh
Dennis Koch
Dennis Kochβ€’2y ago
Your value probably isn't null then
toeknee
toekneeβ€’2y ago
Then you need formatStateUsing()
Dennis Koch
Dennis Kochβ€’2y ago
If there isn't a method called default, I at least expected an error message and not a "didn't work"
Atena.D
Atena.DOPβ€’2y ago
It's now working but does this work for other methods? because I need to use $record in ->hidden() method also but to specify a condition.
toeknee
toekneeβ€’2y ago
Depends on the method, your IDE should show you all available methods
Atena.D
Atena.DOPβ€’2y ago
for example when I have something like this: ->hidden(fn ($record) => $record->factor_type === 'buy') it thows this error: Attempt to read property "factor_type" on null. Although it works for ->default() method
toeknee
toekneeβ€’2y ago
I assume that is on a new form opposed to an edit, you need to check first $record is not null.
Atena.D
Atena.DOPβ€’2y ago
I have 3 records in this table which all of them have factor_type
toeknee
toekneeβ€’2y ago
IT is saying the record is null not the factor_type which means the record hasn't been loaded in Try: fn( MyModel $record) =>
Atena.D
Atena.DOPβ€’2y ago
It again says it's null Argument #1 ($record) must be of type App\Models\Factors, null given, called in
toeknee
toekneeβ€’2y ago
Are you creating or editing a record?
Atena.D
Atena.DOPβ€’2y ago
Actually it is in table builder it's not related to forms
toeknee
toekneeβ€’2y ago
Ugh my bad
Dennis Koch
Dennis Kochβ€’2y ago
You don't have record on a Column basis How would you hide columns on a row level inside a table? πŸ€” That would break the layout
toeknee
toekneeβ€’2y ago
Exactly, you need to format the state on the condition
Want results from more Discord servers?
Add your server