A way to make lazy search ?

I have a db with hundred thousand products. the in-built search freezes the table as it searches on type. I made a text input to make implement the search but it also searches on every letter typed. Is there a way to make the search happen only when the the focus changes or enter is pressed?
Filter::make('search')
->form([
Forms\Components\TextInput::make('product_query')->label('Search Product (Name, SKU)'),
])
->columnSpanFull()
->query(function (Builder $query, array $data): Builder {
return $query->when(
$data['product_query'],
fn (Builder $query): Builder => $query->where('name', 'ilike', "%{$data['product_query']}%")
->orWhere('sku', 'ilike', "%{$data['product_query']}%")
);
}),
Filter::make('search')
->form([
Forms\Components\TextInput::make('product_query')->label('Search Product (Name, SKU)'),
])
->columnSpanFull()
->query(function (Builder $query, array $data): Builder {
return $query->when(
$data['product_query'],
fn (Builder $query): Builder => $query->where('name', 'ilike', "%{$data['product_query']}%")
->orWhere('sku', 'ilike', "%{$data['product_query']}%")
);
}),
2 Replies
Kiran Timsina
Kiran TimsinaOP16mo ago
Never mind, making it reactive() and lazy() worked for me. Though ideally i would like to implement reactiveOnReturn() or something like this. I don't have so much idea on how to do it, but seems like it could be good.
josef
josef16mo ago
not sure if it's the same, but in v3 it would be live(onBlur: true) to only update the state on focus change
Want results from more Discord servers?
Add your server