F
Filamentβ€’15mo ago
d3v1anX

Two TextColumns from same field

Hey guys, I tried to add two TextColumns from the same date field. One with only date, the other with the time. Looks like this:
Tables\Columns\TextColumn::make('start')
->label('Start date (UTC)')
->date()
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('start')
->label('Start time (UTC)')
->time()
->sortable(),
Tables\Columns\TextColumn::make('start')
->label('Start date (UTC)')
->date()
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('start')
->label('Start time (UTC)')
->time()
->sortable(),
there only the second field will be displayed. I tried to change the name and use state for displaying data - this will display both fields, but then it is not sortable / searchable, because the sort field is used from "make".
Tables\Columns\TextColumn::make('start date')
->state(fn (Model $record) => $record->start)
->label('Start date (UTC)')
->date()
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('start')
->label('Start time (UTC)')
->time()
->sortable(),
Tables\Columns\TextColumn::make('start date')
->state(fn (Model $record) => $record->start)
->label('Start date (UTC)')
->date()
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('start')
->label('Start time (UTC)')
->time()
->sortable(),
Is my approach to display two fields of one column correct? Or am I missing something? πŸ™‚ Thank you very much!
2 Replies
krekas
krekasβ€’15mo ago
if you would create an attribute in your model i think then sortable and search should work
code jam
code jamβ€’15mo ago
Try to format the date to your preference by overriding formatStateUsing() function
Want results from more Discord servers?
Add your server