F
Filament14mo ago
lodeki

Searchable not working on date column.

This piece of code seems not to work
TextColumn::make('paid_date')->datetime()->size('sm')->searchable(),
TextColumn::make('paid_date')->datetime()->size('sm')->searchable(),
.Searching by the date does not work .The date format displayed in the table takes this form
Oct 4, 2023 12:48:18
Oct 4, 2023 12:48:18
. Any help or leads ?
11 Replies
Miguel García
Miguel García14mo ago
try searching using your db datetime format, e.g. if you're using mysql, search by 2023-10-4 ...
lodeki
lodekiOP14mo ago
Still not really working
toeknee
toeknee14mo ago
You can't really search data columns if I recall correctly. You would just add a date filter in instead?
Miguel García
Miguel García14mo ago
is your table attached to your own livewire component or to an app resource? I'm able to search by date on date columns, at least it does work for me when the table is attached to an app resource and using the panel builder, but the date format must match the db date format. This is my boot function in my AdminPanelProvider:
public function boot(): void
{
Column::configureUsing(function (Column $column): void {
$column->extraAttributes(['style' => 'min-width: 150px;'])
->searchable(isIndividual: true)
->sortable()
->toggleable();
});
}
public function boot(): void
{
Column::configureUsing(function (Column $column): void {
$column->extraAttributes(['style' => 'min-width: 150px;'])
->searchable(isIndividual: true)
->sortable()
->toggleable();
});
}
and this is my text column:
/**
* @param Filament\Tables\Table $table
* @return Filament\Tables\Table
*/
public static function table(Table $table): Table
{
return $table->columns([
// Other fields, ....
Tables\Columns\TextColumn::make('birthdate')
->date('d/m/Y')
->label(__('employee.labels.birthdate')),
// Other fields, ....
// Filters and so on, ....
...
}
/**
* @param Filament\Tables\Table $table
* @return Filament\Tables\Table
*/
public static function table(Table $table): Table
{
return $table->columns([
// Other fields, ....
Tables\Columns\TextColumn::make('birthdate')
->date('d/m/Y')
->label(__('employee.labels.birthdate')),
// Other fields, ....
// Filters and so on, ....
...
}
Miguel García
Miguel García14mo ago
No description
Miguel García
Miguel García14mo ago
If your table is attached to another livewire component then you migh need to do some work first https://filamentphp.com/docs/3.x/tables/adding-a-table-to-a-livewire-component
Miguel García
Miguel García14mo ago
Maybe you need to cast your paid_date to date (Carbon)
toeknee
toeknee14mo ago
I don't get it, why not add a calendar? That will be a UX Pain?
Miguel García
Miguel García14mo ago
A filter with a calendar or two calendars (date from/date until) would be a solution of course. But what if you do not want to add such a filter? Is it possible to use the built in search widget or not?
toeknee
toeknee14mo ago
I am not sure it allows it if I am honest as you need to have an exact date / time for that column to search it. Otherwise you are searching numbers etc.
Miguel García
Miguel García14mo ago
ok, ok, as long as we can customise the search function (using a closure) or we can create filters it shouldn't be a problem, quite powerful, thank mate!
Want results from more Discord servers?
Add your server